13 changed files with 825 additions and 10 deletions
@ -0,0 +1,180 @@ |
|||||
|
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 NgRepairBlobsController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public NgRepairBlobsController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgRepairBlobs
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<NgRepairBlob>>> GetNgRepairBlob() |
||||
|
{ |
||||
|
return await _context.NgRepairBlobs.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgRepairBlobs/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<NgRepairBlob>>> GetNgRepairBlob(int id) |
||||
|
{ |
||||
|
IQueryable<NgRepairBlob> q = _context.NgRepairBlobs; |
||||
|
q = q.Where(p => p.RepairID.Equals(id)); |
||||
|
|
||||
|
var ngRepairBlob = await q.ToListAsync(); |
||||
|
|
||||
|
if (ngRepairBlob == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return ngRepairBlob; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="ngRepairBlob"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/NgRepairBlobs/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("{id}")] |
||||
|
public async Task<ResultModel<NgRepairBlob>> PutNgRepairBlob(int id, NgRepairBlob ngRepairBlob) |
||||
|
{ |
||||
|
ResultModel<NgRepairBlob> result = new ResultModel<NgRepairBlob>(); |
||||
|
|
||||
|
if (id != ngRepairBlob.RepairID) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.Entry(ngRepairBlob).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!NgRepairBlobExists(id)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="ngRepairBlob"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/NgRepairBlobs
|
||||
|
// 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<NgRepairBlob>> PostNgRepairBlob(NgRepairBlob ngRepairBlob) |
||||
|
{ |
||||
|
ResultModel<NgRepairBlob> result = new ResultModel<NgRepairBlob>(); |
||||
|
|
||||
|
_context.NgRepairBlobs.Add(ngRepairBlob); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
if (NgRepairBlobExists(ngRepairBlob.RepairID)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID重複"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/NgRepairBlobs/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ResultModel<NgRepairBlob>> DeleteNgRepairBlob(decimal id) |
||||
|
{ |
||||
|
ResultModel<NgRepairBlob> result = new ResultModel<NgRepairBlob>(); |
||||
|
|
||||
|
var ngRepairBlob = await _context.NgRepairBlobs.FindAsync(id); |
||||
|
if (ngRepairBlob == null) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.NgRepairBlobs.Remove(ngRepairBlob); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private bool NgRepairBlobExists(decimal id) |
||||
|
{ |
||||
|
return _context.NgRepairBlobs.Any(e => e.RepairID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,205 @@ |
|||||
|
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 NgRepairsController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public NgRepairsController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgRepairs
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<NgRepair>>> GetNgRepair() |
||||
|
{ |
||||
|
return await _context.NgRepairs.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgRepairs/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<NgRepair>>> GetNgRepair(int id) |
||||
|
{ |
||||
|
IQueryable<NgRepair> q = _context.NgRepairs; |
||||
|
q = q.Where(p => p.RepairID.Equals(id)); |
||||
|
|
||||
|
var ngRepair = await q.ToListAsync(); |
||||
|
|
||||
|
if (ngRepair == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return ngRepair; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgRepairs/5
|
||||
|
[HttpGet("Component/{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<NgRepair>>> GetNgRepairByComponent(int id) |
||||
|
{ |
||||
|
IQueryable<NgRepair> q = _context.NgRepairs; |
||||
|
q = q.Where(p => p.ComponentID.Equals(id)); |
||||
|
|
||||
|
var ngRepair = await q.ToListAsync(); |
||||
|
|
||||
|
if (ngRepair == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return ngRepair; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="ngRepair"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/NgRepairs/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("{id}")] |
||||
|
public async Task<ResultModel<NgRepair>> PutNgRepair(int id, NgRepair ngRepair) |
||||
|
{ |
||||
|
ResultModel<NgRepair> result = new ResultModel<NgRepair>(); |
||||
|
|
||||
|
if (id != ngRepair.RepairID) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.Entry(ngRepair).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!NgRepairExists(id)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="ngRepair"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/NgRepairs
|
||||
|
// 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<NgRepair>> PostNgRepair(NgRepair ngRepair) |
||||
|
{ |
||||
|
ResultModel<NgRepair> result = new ResultModel<NgRepair>(); |
||||
|
|
||||
|
Helper helper = new Helper(_context); |
||||
|
ngRepair.RepairID = helper.GetIDKey("REPAIR_ID").Result; |
||||
|
|
||||
|
_context.NgRepairs.Add(ngRepair); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
if (NgRepairExists(ngRepair.RepairID)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID重複"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/NgRepairs/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ResultModel<NgRepair>> DeleteNgRepair(decimal id) |
||||
|
{ |
||||
|
ResultModel<NgRepair> result = new ResultModel<NgRepair>(); |
||||
|
|
||||
|
var ngRepair = await _context.NgRepairs.FindAsync(id); |
||||
|
if (ngRepair == null) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良維修ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.NgRepairs.Remove(ngRepair); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private bool NgRepairExists(decimal id) |
||||
|
{ |
||||
|
return _context.NgRepairs.Any(e => e.RepairID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,178 @@ |
|||||
|
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 RepairRecordsController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public RepairRecordsController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/RepairRecords
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<RepairRecord>>> GetRepairRecord() |
||||
|
{ |
||||
|
return await _context.RepairRecords.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/RepairRecords/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<RepairRecord>>> GetRepairRecord(int id) |
||||
|
{ |
||||
|
IQueryable<RepairRecord> q = _context.RepairRecords; |
||||
|
q = q.Where(p => p.ComponentID.Equals(id)); |
||||
|
|
||||
|
var repairRecord = await q.ToListAsync(); |
||||
|
|
||||
|
if (repairRecord == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return repairRecord; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="repairRecord"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/RepairRecords/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("{id}")] |
||||
|
public async Task<ResultModel<RepairRecord>> PutRepairRecord(int id, RepairRecord repairRecord) |
||||
|
{ |
||||
|
ResultModel<RepairRecord> result = new ResultModel<RepairRecord>(); |
||||
|
if (id != repairRecord.ComponentID) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良零件ID錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.Entry(repairRecord).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!RepairRecordExists(id)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良零件ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="repairRecord"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/RepairRecords
|
||||
|
// 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<RepairRecord>> PostRepairRecord(RepairRecord repairRecord) |
||||
|
{ |
||||
|
ResultModel<RepairRecord> result = new ResultModel<RepairRecord>(); |
||||
|
|
||||
|
_context.RepairRecords.Add(repairRecord); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
if (RepairRecordExists(repairRecord.ComponentID)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良零件ID重複"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/RepairRecords/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ResultModel<RepairRecord>> DeleteRepairRecord(decimal id) |
||||
|
{ |
||||
|
ResultModel<RepairRecord> result = new ResultModel<RepairRecord>(); |
||||
|
var repairRecord = await _context.RepairRecords.FindAsync(id); |
||||
|
if (repairRecord == null) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "不良零件ID不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.RepairRecords.Remove(repairRecord); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private bool RepairRecordExists(decimal id) |
||||
|
{ |
||||
|
return _context.RepairRecords.Any(e => e.ComponentID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue