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.
159 lines
5.1 KiB
159 lines
5.1 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;
|
|
using AMESCoreStudio.WebApi.DTO.AMES;
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES
|
|
{
|
|
/// <summary>
|
|
/// FQC檢驗項目群組綁定設定檔
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class FqcItemController : ControllerBase
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
public FqcItemController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<FqcItem>>> GetFqcItems()
|
|
{
|
|
return await _context.FqcItems.ToListAsync();
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<FqcItem>> GetFqcItem(int id)
|
|
{
|
|
var fqcItem = await _context.FqcItems.FindAsync(id);
|
|
return fqcItem;
|
|
}
|
|
|
|
/// <summary>
|
|
/// FQC檢驗項目群組綁定設定檔 to GroupID(FQC檢驗群組)
|
|
/// </summary>
|
|
/// <param name="id">料號</param>
|
|
/// <returns></returns>
|
|
[HttpGet("ByFqcGroupId/{id}")]
|
|
public async Task<IEnumerable<FqcItem>> GetFqcItemByFqcGroupId(int id)
|
|
{
|
|
IQueryable<FqcItem> q = _context.FqcItems;
|
|
var result = await q.Where(p => p.GroupId == id).ToListAsync();
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 料號查詢FQC檢驗群組及綁定檢驗工項
|
|
/// </summary>
|
|
/// <param name="id">料號</param>
|
|
/// <returns></returns>
|
|
[HttpGet("ByItemNo/{id}")]
|
|
public async Task<ActionResult<IEnumerable<FqcItem>>> GetFqcItemByItemNo(string id)
|
|
{
|
|
var itemID = 0;
|
|
var result = await _context.MaterialItems.Where(w => w.ItemNo == id).ToListAsync();
|
|
if (result.Count() != 0)
|
|
itemID = result.FirstOrDefault().ItemID;
|
|
|
|
var q = from q1 in _context.FqcItems
|
|
join q2 in _context.FqcItemGroupMaterials on q1.GroupId equals q2.GroupId where q2.ItemId == itemID
|
|
select q1;
|
|
|
|
return await q.ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新檢驗項目群組綁定設定檔
|
|
/// </summary>
|
|
/// <param name="fqcItem"></param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<FqcItem>> PutFqcItem(FqcItem fqcItem)
|
|
{
|
|
ResultModel<FqcItem> result = new ResultModel<FqcItem>();
|
|
_context.Entry(fqcItem).State = EntityState.Modified;
|
|
_context.Entry<FqcItem>(fqcItem).Property("CreateDate").IsModified = false;
|
|
_context.Entry<FqcItem>(fqcItem).Property("CreateUserID").IsModified = false;
|
|
fqcItem.UpdateDate = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增檢驗項目群組綁定設定檔
|
|
/// </summary>
|
|
/// <param name="fqcItem"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<FqcItem>> PostFqcItem(FqcItem fqcItem)
|
|
{
|
|
ResultModel<FqcItem> result = new ResultModel<FqcItem>();
|
|
Helper helper = new Helper(_context);
|
|
fqcItem.FqcItemId = helper.GetIDKey("FQC_ITEM_ID").Result;
|
|
_context.FqcItems.Add(fqcItem);
|
|
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/FqcItem/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<ResultModel<string>> DeleteFqcItem(int id)
|
|
{
|
|
ResultModel<string> result = new ResultModel<string>();
|
|
var fqcItem = await _context.FqcItems.FindAsync(id);
|
|
|
|
try
|
|
{
|
|
if (fqcItem == null)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = "找不到要刪除資料";
|
|
}
|
|
else
|
|
{
|
|
_context.FqcItems.Remove(fqcItem);
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|