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.
140 lines
4.5 KiB
140 lines
4.5 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>
|
|
/// 檢驗單結果資料檔
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class FqcResultMasterController : ControllerBase
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
public FqcResultMasterController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// GET: api/FqcResultMaster
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<FqcResultMaster>>> GetFqcResultMasters()
|
|
{
|
|
return await _context.FqcResultMasters.ToListAsync();
|
|
}
|
|
|
|
// GET: api/FqcResultMaster/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<FqcResultMaster>> GetFqcResultMaster(int id)
|
|
{
|
|
var fqcResultMaster = await _context.FqcResultMasters.FindAsync(id);
|
|
return fqcResultMaster;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用入庫單號 and 序號找資料
|
|
/// </summary>
|
|
/// <param name="inhouseNo">入庫單號</param>
|
|
/// <param name="seq">序號</param>
|
|
/// <returns></returns>
|
|
[HttpGet("ByInhouseNo/{inhouseNo}/{seq}")]
|
|
public async Task<ActionResult<IEnumerable<FqcResultMaster>>> GetFqcResultMasterByInhouseNo(string inhouseNo , int seq)
|
|
{
|
|
var fqcResultMaster = await _context.FqcResultMasters
|
|
.Where(w => w.InhouseNo == inhouseNo && w.SeqID == seq)
|
|
.ToListAsync();
|
|
|
|
//if (fqcResultMaster == null)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
return fqcResultMaster;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新FQC檢驗單結果
|
|
/// </summary>
|
|
/// <param name="fqcResultMaster"></param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<FqcResultMaster>> PutFqcResultMaster(FqcResultMaster fqcResultMaster)
|
|
{
|
|
ResultModel<FqcResultMaster> result = new ResultModel<FqcResultMaster>();
|
|
_context.Entry(fqcResultMaster).State = EntityState.Modified;
|
|
fqcResultMaster.UpdateDate = DateTime.Now;
|
|
fqcResultMaster.UpdateUserID = 0;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增FQC檢驗單結果
|
|
/// </summary>
|
|
/// <param name="fqcResultMaster"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<FqcResultMaster>> PostFqcResultMaster(FqcResultMaster fqcResultMaster)
|
|
{
|
|
ResultModel<FqcResultMaster> result = new ResultModel<FqcResultMaster>();
|
|
Helper helper = new Helper(_context);
|
|
fqcResultMaster.FqcID = helper.GetIDKey("FQC_ID").Result;
|
|
_context.FqcResultMasters.Add(fqcResultMaster);
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Data = new List<FqcResultMaster> { fqcResultMaster };
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// DELETE: api/FqcResultMaster/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<ActionResult<FqcResultMaster>> DeleteFqcResultMaster(int id)
|
|
{
|
|
var fqcResultMaster = await _context.FqcResultMasters.FindAsync(id);
|
|
if (fqcResultMaster == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
_context.FqcResultMasters.Remove(fqcResultMaster);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return fqcResultMaster;
|
|
}
|
|
|
|
private bool FqcResultMasterExists(int id)
|
|
{
|
|
return _context.FqcResultMasters.Any(e => e.FqcID == id);
|
|
}
|
|
}
|
|
}
|
|
|