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 { /// /// FQC檢驗結果明細資料檔 /// [Route("api/[controller]")] [ApiController] public class FqcResultDetailController : ControllerBase { private readonly AMESContext _context; public FqcResultDetailController(AMESContext context) { _context = context; } // GET: api/FqcResultDetail [HttpGet] public async Task>> GetFqcResultDetails() { return await _context.FqcResultDetails.ToListAsync(); } /// /// /// /// FQCID /// [HttpGet("{id}")] public async Task>> GetFqcResultDetail(int id) { var fqcResultDetail = await _context.FqcResultDetails.Where(w => w.FqcID == id).ToListAsync(); return fqcResultDetail; } /// /// 更新FQC檢驗結果明細 /// /// /// [HttpPut] public async Task> PutFqcResultDetail(FqcResultDetail fqcResultDetail) { ResultModel result = new ResultModel(); _context.Entry(fqcResultDetail).State = EntityState.Modified; fqcResultDetail.UpdateDate = DateTime.Now; fqcResultDetail.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; } /// /// 新增FQC檢驗結果明細 /// /// /// [HttpPost] public async Task> PostFqcResultDetail(FqcResultDetail fqcResultDetail) { ResultModel result = new ResultModel(); _context.FqcResultDetails.Add(fqcResultDetail); try { await _context.SaveChangesAsync(); result.Success = true; result.Msg = "OK"; } catch (Exception ex) { result.Success = false; result.Msg = ex.InnerException.Message; } return result; } // DELETE: api/FqcResultDetail/5 [HttpDelete("{id}")] public async Task> DeleteFqcResultDetail(int id) { var fqcResultDetail = await _context.FqcResultDetails.FindAsync(id); if (fqcResultDetail == null) { return NotFound(); } _context.FqcResultDetails.Remove(fqcResultDetail); await _context.SaveChangesAsync(); return fqcResultDetail; } private bool FqcResultDetailExists(int id) { return _context.FqcResultDetails.Any(e => e.FqcID == id); } } }