using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using AMESCoreStudio.WebApi.Models.AMES; using AMESCoreStudio.CommonTools.Result; namespace AMESCoreStudio.WebApi.Controllers.AMES { /// /// /// [Route("api/[controller]")] [ApiController] public class WipAttsController : Controller { private readonly AMESContext _context; /// /// /// /// public WipAttsController(AMESContext context) { _context = context; } /// /// 查詢工單資料Att /// /// // GET: api/WipAtts [HttpGet] public async Task>> GetWipAtt() { IQueryable q = _context.WipAtts; q = q.OrderBy(p => p.WipNO); //q = q.OrderByDescending(p => p.SystemID); var WipAtt = await q.ToListAsync(); //return await _context.SystemInfoes.ToListAsync(); return WipAtt; } /// /// 查詢工單資料Att By WipNO /// /// 工單號碼 /// // GET: api/WipAtts/4 [HttpGet("{id}")] public async Task> GetWipAtt(string id) { IQueryable q = _context.WipAtts.Where(p => p.WipNO == id); var WipAtt = await q.ToListAsync(); if (WipAtt == null || WipAtt.Count == 0) { return NotFound(); } return WipAtt.FirstOrDefault(); } /// /// 新增工單資料Att /// /// /// // POST: api/WipAtts // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. [HttpPost] public async Task> PostWipAtt([FromBody] WipAtt wipatt) { ResultModel result = new ResultModel(); wipatt.CreateUserID = 0; _context.WipAtts.Add(wipatt); try { await _context.SaveChangesAsync(); result.Success = true; result.Msg = "OK"; } catch (Exception ex) { result.Success = false; result.Msg = ex.InnerException.Message; } return result; } } }