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

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 LabelRPrintDetailController : ControllerBase
{
private readonly AMESContext _context;
public LabelRPrintDetailController(AMESContext context)
{
_context = context;
}
// GET: api/LabelRPrintDetail
[HttpGet]
public async Task<ActionResult<IEnumerable<LabelRPrintDetail>>> GetLabelRPrintDetails()
{
return await _context.LabelRPrintDetail.ToListAsync();
}
// GET: api/LabelRPrintDetail/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<LabelRPrintDetail>>> GetLabelRPrintDetail(int id)
{
IQueryable<LabelRPrintDetail> q = _context.LabelRPrintDetail;
q = q.Where(p => p.LabelRPrintDetailID.Equals(id));
var LabelRPrintDetail = await q.ToListAsync();
if (LabelRPrintDetail == null)
{
return NotFound();
}
return LabelRPrintDetail;
}
/// <summary>
/// 更新Label補印參數檔
/// </summary>
/// <param name="LabelRPrintDetail"></param>
/// <returns></returns>
[HttpPut]
public async Task<ResultModel<LabelRPrintDetail>> PutLabelRPrintDetail(LabelRPrintDetail LabelRPrintDetail)
{
ResultModel<LabelRPrintDetail> result = new ResultModel<LabelRPrintDetail>();
_context.Entry(LabelRPrintDetail).State = EntityState.Modified;
//設置容器空間某一個模型的某一個欄位 不提交到資料庫
_context.Entry<LabelRPrintDetail>(LabelRPrintDetail).Property("CreateDate").IsModified = false;
_context.Entry<LabelRPrintDetail>(LabelRPrintDetail).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="LabelRPrintDetail"></param>
/// <returns></returns>
[HttpPost]
public async Task<ResultModel<LabelRPrintDetail>> PostLabelRPrintDetail(List<LabelRPrintDetail> LabelRPrintDetail)
{
ResultModel<LabelRPrintDetail> result = new ResultModel<LabelRPrintDetail>();
try
{
IQueryable<LabelRPrintDetail> q = _context.LabelRPrintDetail;
Helper helper = new Helper(_context);
foreach (var item in LabelRPrintDetail)
{
item.LabelRPrintDetailID = helper.GetIDKey("LABELPRINT_DETAIL_ID").Result;
item.CreateDate = DateTime.Now;
_context.LabelRPrintDetail.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/LabelRPrintDetail/5
[HttpDelete("{id}")]
public async Task<ResultModel<LabelRPrintDetail>> DeleteLabelRPrintDetail(int id)
{
ResultModel<LabelRPrintDetail> result = new ResultModel<LabelRPrintDetail>();
var query = await _context.LabelRPrintDetail.Where(w => w.LabelRPrintDetailID == id).ToListAsync();
try
{
_context.LabelRPrintDetail.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 LabelRPrintDetailExists(int id)
{
return _context.LabelRPrintDetail.Any(e => e.LabelRPrintDetailID == id);
}
}
}