You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
4.7 KiB
143 lines
4.7 KiB
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;
|
|
using AMESCoreStudio.CommonTools.Result;
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES
|
|
{
|
|
/// <summary>
|
|
/// FQC檢驗結果ID
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class LabelPrintDetailController : ControllerBase
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
public LabelPrintDetailController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// GET: api/LabelPrintDetail
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<LabelPrintDetail>>> GetLabelPrintDetails()
|
|
{
|
|
return await _context.LabelPrintDetail.ToListAsync();
|
|
}
|
|
|
|
// GET: api/LabelPrintDetail/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<IEnumerable<LabelPrintDetail>>> GetLabelPrintDetail(int id)
|
|
{
|
|
IQueryable<LabelPrintDetail> q = _context.LabelPrintDetail;
|
|
q = q.Where(p => p.LabelPrintDetailID.Equals(id));
|
|
var LabelPrintdetail = await q.ToListAsync();
|
|
|
|
if (LabelPrintdetail == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return LabelPrintdetail;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新Label參數檔
|
|
/// </summary>
|
|
/// <param name="LabelPrintDetail"></param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<LabelPrintDetail>> PutLabelPrintDetail(LabelPrintDetail LabelPrintDetail)
|
|
{
|
|
ResultModel<LabelPrintDetail> result = new ResultModel<LabelPrintDetail>();
|
|
_context.Entry(LabelPrintDetail).State = EntityState.Modified;
|
|
//設置容器空間某一個模型的某一個欄位 不提交到資料庫
|
|
_context.Entry<LabelPrintDetail>(LabelPrintDetail).Property("CreateDate").IsModified = false;
|
|
_context.Entry<LabelPrintDetail>(LabelPrintDetail).Property("CreateUserID").IsModified = false;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增更新Label參數檔
|
|
/// </summary>
|
|
/// <param name="LabelPrintDetail"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<LabelPrintDetail>> PostLabelPrintDetail(List<LabelPrintDetail> LabelPrintDetail)
|
|
{
|
|
ResultModel<LabelPrintDetail> result = new ResultModel<LabelPrintDetail>();
|
|
|
|
try
|
|
{
|
|
IQueryable<LabelPrintDetail> q = _context.LabelPrintDetail;
|
|
Helper helper = new Helper(_context);
|
|
foreach (var item in LabelPrintDetail)
|
|
{
|
|
item.LabelPrintDetailID = helper.GetIDKey("LABELPRINT_DETAIL_ID").Result;
|
|
item.CreateDate = DateTime.Now;
|
|
_context.LabelPrintDetail.Add(item);
|
|
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
// DELETE: api/LabelPrintDetail/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<ResultModel<LabelPrintDetail>> DeleteLabelPrintDetail(int id)
|
|
{
|
|
|
|
ResultModel<LabelPrintDetail> result = new ResultModel<LabelPrintDetail>();
|
|
var query = await _context.LabelPrintDetail.Where(w => w.LabelPrintDetailID == id).ToListAsync();
|
|
try
|
|
{
|
|
_context.LabelPrintDetail.RemoveRange(query);
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private bool LabelPrintDetailExists(int id)
|
|
{
|
|
return _context.LabelPrintDetail.Any(e => e.LabelPrintDetailID == id);
|
|
}
|
|
}
|
|
}
|
|
|