5 changed files with 301 additions and 2 deletions
@ -0,0 +1,156 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using AMESCoreStudio.WebApi; |
||||
|
using AMESCoreStudio.WebApi.Models.AMES; |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Controllers.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
[Route("api/[controller]")]
|
||||
|
[ApiController] |
||||
|
public class CalendarTablesController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public CalendarTablesController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/CalendarTables
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<CalendarTable>>> GetCalendarTable() |
||||
|
{ |
||||
|
return await _context.CalendarTables.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/CalendarTables/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<CalendarTable>> GetCalendarTable(DateTime id) |
||||
|
{ |
||||
|
var calendarTable = await _context.CalendarTables.FindAsync(id); |
||||
|
|
||||
|
if (calendarTable == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return calendarTable; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="calendarTable"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/CalendarTables/5
|
||||
|
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
|
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
|
||||
|
[HttpPut("{id}")] |
||||
|
public async Task<IActionResult> PutCalendarTable(DateTime id, CalendarTable calendarTable) |
||||
|
{ |
||||
|
if (id != calendarTable.TimeID) |
||||
|
{ |
||||
|
return BadRequest(); |
||||
|
} |
||||
|
|
||||
|
_context.Entry(calendarTable).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!CalendarTableExists(id)) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return NoContent(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="calendarTable"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/CalendarTables
|
||||
|
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
|
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
|
||||
|
[HttpPost] |
||||
|
public async Task<ActionResult<CalendarTable>> PostCalendarTable(CalendarTable calendarTable) |
||||
|
{ |
||||
|
_context.CalendarTables.Add(calendarTable); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
if (CalendarTableExists(calendarTable.TimeID)) |
||||
|
{ |
||||
|
return Conflict(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return CreatedAtAction("GetCalendarTable", new { id = calendarTable.TimeID }, calendarTable); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/CalendarTables/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ActionResult<CalendarTable>> DeleteCalendarTable(DateTime id) |
||||
|
{ |
||||
|
var calendarTable = await _context.CalendarTables.FindAsync(id); |
||||
|
if (calendarTable == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
_context.CalendarTables.Remove(calendarTable); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
return calendarTable; |
||||
|
} |
||||
|
|
||||
|
private bool CalendarTableExists(DateTime id) |
||||
|
{ |
||||
|
return _context.CalendarTables.Any(e => e.TimeID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,133 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using System.Runtime.Serialization; |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Models.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 日曆
|
||||
|
/// </summary>
|
||||
|
[Table("CALENDAR_TABLE", Schema = "JHAMES")] |
||||
|
public class CalendarTable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 時間
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("TIME_ID")] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "時間")] |
||||
|
[DataMember] |
||||
|
public DateTime TimeID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 年份
|
||||
|
/// </summary>
|
||||
|
[Column("YEAR")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "年份")] |
||||
|
public string Year { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 月份
|
||||
|
/// </summary>
|
||||
|
[Column("MONTH")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "月份")] |
||||
|
public string Month { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 日期
|
||||
|
/// </summary>
|
||||
|
[Column("DAY")] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "日期")] |
||||
|
[DataMember] |
||||
|
public string Day { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 月份描述
|
||||
|
/// </summary>
|
||||
|
[Column("MONTH_NAME")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "月份描述")] |
||||
|
public string MonthName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 日期描述
|
||||
|
/// </summary>
|
||||
|
[Column("DAY_NAME")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "日期描述")] |
||||
|
public string DayName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當月第幾周
|
||||
|
/// </summary>
|
||||
|
[Column("WEEK_OF_MONTH")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當月第幾周")] |
||||
|
public int WeekOfMonth { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當年第幾周(ISO)
|
||||
|
/// </summary>
|
||||
|
[Column("WEEK_OF_YEAR_ISO")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當年第幾周(ISO)")] |
||||
|
public int WeekOfYearISO { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當月最後一天
|
||||
|
/// </summary>
|
||||
|
[Column("MONTH_END_DAY")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當月最後一天")] |
||||
|
public DateTime MonthEndDay { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 週日期起訖
|
||||
|
/// </summary>
|
||||
|
[Column("WEEK_RANGE")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "週日期起訖")] |
||||
|
public string WeekRange { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當年第幾周
|
||||
|
/// </summary>
|
||||
|
[Column("WEEK_OF_YEAR")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當年第幾周")] |
||||
|
public int WeekOfYear { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當年第幾周(客戶)
|
||||
|
/// </summary>
|
||||
|
[Column("WEEK_OF_YEAR_ADVANTECH")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當年第幾周(客戶)")] |
||||
|
public int WeekOfYearAdvantech { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 假日
|
||||
|
/// </summary>
|
||||
|
[Column("HOLIDAY")] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "假日")] |
||||
|
[StringLength(2, ErrorMessage = "{0},不能大于{1}")] |
||||
|
[DataMember] |
||||
|
public string Holiday { get; set; } |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue