15 changed files with 662 additions and 368 deletions
@ -0,0 +1,182 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using AMESCoreStudio.WebApi.Models.AMES; |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Controllers.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 條碼狀態維護
|
||||
|
/// </summary>
|
||||
|
[Route("api/[controller]")]
|
||||
|
[ApiController] |
||||
|
public class BarcodeTypeController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public BarcodeTypeController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/BarcodeType
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeType>>> GetBarcodeType() |
||||
|
{ |
||||
|
IQueryable<BarcodeType> q = _context.BarcodeTypes; |
||||
|
q = q.OrderBy(p => p.BarcodeTypeID); |
||||
|
|
||||
|
var BarcodeType = await q.ToListAsync(); |
||||
|
return BarcodeType; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/BarcodeType/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeType>>> GetBarcodeType(string id) |
||||
|
{ |
||||
|
IQueryable<BarcodeType> q = _context.BarcodeTypes; |
||||
|
q = q.Where(p => p.BarcodeTypeID.Equals(id)); |
||||
|
|
||||
|
var BarcodeType = await q.ToListAsync(); |
||||
|
|
||||
|
if (BarcodeType == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return BarcodeType; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/BarcodeType/5
|
||||
|
[HttpGet("TypeName/{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeType>>> GetBarcodeTypeByTypeName(string id) |
||||
|
{ |
||||
|
IQueryable<BarcodeType> q = _context.BarcodeTypes; |
||||
|
q = q.Where(p => p.TypeName.Equals(id)); |
||||
|
|
||||
|
var BarcodeType = await q.ToListAsync(); |
||||
|
|
||||
|
if (BarcodeType == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return BarcodeType; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="BarcodeType"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/BarcodeType/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<ActionResult<BarcodeType>> PutBarcodeType(int id, [FromBody] BarcodeType BarcodeType) |
||||
|
{ |
||||
|
if (id != BarcodeType.BarcodeTypeID) |
||||
|
{ |
||||
|
return BadRequest(); |
||||
|
} |
||||
|
|
||||
|
_context.Entry(BarcodeType).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!BarcodeTypeExists(id)) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return BarcodeType; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="BarcodeType"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/BarcodeType
|
||||
|
// 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<BarcodeType>> PostBarcodeType([FromBody] BarcodeType BarcodeType) |
||||
|
{ |
||||
|
_context.BarcodeTypes.Add(BarcodeType); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
if (BarcodeTypeExists(BarcodeType.BarcodeTypeID)) |
||||
|
{ |
||||
|
return Conflict(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return CreatedAtAction("GetBarcodeType", new { id = BarcodeType.BarcodeTypeID }, BarcodeType); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/BarcodeType/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ActionResult<BarcodeType>> DeleteBarcodeType(int id) |
||||
|
{ |
||||
|
var BarcodeType = await _context.BarcodeTypes.Where(p => p.BarcodeTypeID == id).FirstOrDefaultAsync(); |
||||
|
if (BarcodeType == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
_context.BarcodeTypes.Remove(BarcodeType); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
return BarcodeType; |
||||
|
} |
||||
|
|
||||
|
private bool BarcodeTypeExists(int id) |
||||
|
{ |
||||
|
return _context.BarcodeTypes.Any(e => e.BarcodeTypeID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,82 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using System.Runtime.Serialization; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Models.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 條碼類別資料檔
|
||||
|
/// </summary>
|
||||
|
[Table("BARCODE_TYPE", Schema = "JHAMES")] |
||||
|
public partial class BarcodeType |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 條碼類別ID
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("BARCODE_TYPE_ID", TypeName = "NUMBER")] |
||||
|
[DataMember] |
||||
|
public int BarcodeTypeID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 類別代碼
|
||||
|
/// </summary>
|
||||
|
|
||||
|
[Column("TYPE_NO")] |
||||
|
[StringLength(4)] |
||||
|
[Display(Name = "類別代碼")] |
||||
|
[DataMember] |
||||
|
public string TypeNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 類別描述
|
||||
|
/// </summary>
|
||||
|
[Column("TYPE_NAME")] |
||||
|
[StringLength(50)] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "類別描述")] |
||||
|
[DataMember] |
||||
|
public string TypeName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 當前值
|
||||
|
/// </summary>
|
||||
|
[Column("BARCODE_QTY")] |
||||
|
[StringLength(10)] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "當前值")] |
||||
|
[DataMember] |
||||
|
public string BarcodeQty { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 創建者ID
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 創建日期
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime CreateDate { get; set; } = System.DateTime.Now; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新者ID
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int UpdateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新日期
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_DATE", TypeName = "DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime UpdateDate { get; set; } = System.DateTime.Now; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue