9 changed files with 309 additions and 68 deletions
@ -0,0 +1,146 @@ |
|||||
|
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 BarcodeStationController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
public BarcodeStationController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
// GET: api/BarcodeStation
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeStation>>> GetBarcodeStation() |
||||
|
{ |
||||
|
return await _context.BarcodeStation.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
// GET: api/BarcodeStation/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<BarcodeStation>> GetBarcodeStation(decimal id) |
||||
|
{ |
||||
|
var barcodeStation = await _context.BarcodeStation.FindAsync(id); |
||||
|
|
||||
|
if (barcodeStation == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return barcodeStation; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="barcodeID">內務條碼ID</param>
|
||||
|
/// <param name="wipID">工單ID</param>
|
||||
|
/// <param name="ruleStationID">流程站別ID</param>
|
||||
|
/// <param name="ruleStatus"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/BarcodeStation/5
|
||||
|
[HttpGet("Key")] |
||||
|
public async Task<ActionResult<BarcodeStation>> GetBarcodeStationByKey(decimal barcodeID, decimal wipID |
||||
|
, decimal ruleStationID, string ruleStatus) |
||||
|
{ |
||||
|
var barcodeStation = await _context.BarcodeStation |
||||
|
.Where(w => w.BarcodeID == barcodeID |
||||
|
&& w.WipID == wipID |
||||
|
&& w.RuleStationID == ruleStationID |
||||
|
&& w.RuleStatus == ruleStatus).FirstOrDefaultAsync(); |
||||
|
|
||||
|
|
||||
|
if (barcodeStation == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return barcodeStation; |
||||
|
} |
||||
|
|
||||
|
// PUT: api/BarcodeStation/5
|
||||
|
// 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.
|
||||
|
[HttpPut] |
||||
|
public async Task<ResultModel<BarcodeStation>> PutBarcodeStation([FromBody]BarcodeStation barcodeStation) |
||||
|
{ |
||||
|
ResultModel<BarcodeStation> result = new ResultModel<BarcodeStation>(); |
||||
|
_context.Attach(barcodeStation); |
||||
|
|
||||
|
// 指定更新某個欄位
|
||||
|
_context.Entry(barcodeStation).Property(p => p.LineId).IsModified = true; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = ex.Message; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// POST: api/BarcodeStation
|
||||
|
// 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<ResultModel<BarcodeStation>> PostBarcodeStation([FromBody] BarcodeStation barcodeStation) |
||||
|
{ |
||||
|
ResultModel<BarcodeStation> result = new ResultModel<BarcodeStation>(); |
||||
|
_context.BarcodeStation.Add(barcodeStation); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = ex.Message; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// DELETE: api/BarcodeStation/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ActionResult<BarcodeStation>> DeleteBarcodeStation(decimal id) |
||||
|
{ |
||||
|
var barcodeStation = await _context.BarcodeStation.FindAsync(id); |
||||
|
if (barcodeStation == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
_context.BarcodeStation.Remove(barcodeStation); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
return barcodeStation; |
||||
|
} |
||||
|
|
||||
|
private bool BarcodeStationExists(decimal id) |
||||
|
{ |
||||
|
return _context.BarcodeStation.Any(e => e.BarcodeID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue