10 changed files with 380 additions and 57 deletions
@ -0,0 +1,138 @@ |
|||
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; |
|||
using AMESCoreStudio.WebApi.DTO.AMES; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|||
{ |
|||
/// <summary>
|
|||
/// 料號治具資訊資料檔
|
|||
/// </summary>
|
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class MaterialOutfitController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
/// <summary>
|
|||
/// 建構式
|
|||
/// </summary>
|
|||
public MaterialOutfitController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 查詢料號治具資訊資料檔
|
|||
/// </summary>
|
|||
// GET: api/MaterialOutfits
|
|||
[HttpGet] |
|||
public async Task<ActionResult<IEnumerable<MaterialOutfit>>> GetMaterialOutfits() |
|||
{ |
|||
return await _context.MaterialOutfits.ToListAsync(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// GET: api/MaterialOutfits/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<MaterialOutfit>> GetMaterialOutfit(int id) |
|||
{ |
|||
var materialOutfit = await _context.MaterialOutfits.FindAsync(id); |
|||
|
|||
if (materialOutfit == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return materialOutfit; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 料號基本資料檔 to ItemID
|
|||
/// </summary>
|
|||
/// <param name="id">ItemID</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("ByItemID/{id}")] |
|||
public async Task<IEnumerable<MaterialOutfit>> GetMaterialOutfitByItemID(int id) |
|||
{ |
|||
IQueryable<MaterialOutfit> q = _context.MaterialOutfits; |
|||
var result = await q.Where(p => p.ItemID == id).ToListAsync(); |
|||
return result; |
|||
} |
|||
|
|||
// PUT: api/MaterialOutfits/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<IActionResult> PutMaterialOutfit(int id, MaterialOutfit materialOutfit) |
|||
{ |
|||
if (id != materialOutfit.MaterialOutfitID) |
|||
{ |
|||
return BadRequest(); |
|||
} |
|||
|
|||
_context.Entry(materialOutfit).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateConcurrencyException) |
|||
{ |
|||
if (!MaterialOutfitExists(id)) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
return NoContent(); |
|||
} |
|||
|
|||
// POST: api/MaterialOutfits
|
|||
// 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<ActionResult<MaterialOutfit>> PostMaterialOutfit(MaterialOutfit materialOutfit) |
|||
{ |
|||
_context.MaterialOutfits.Add(materialOutfit); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return CreatedAtAction("GetMaterialOutfit", new { id = materialOutfit.MaterialOutfitID }, materialOutfit); |
|||
} |
|||
|
|||
// DELETE: api/MaterialOutfits/5
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ActionResult<MaterialOutfit>> DeleteMaterialOutfit(int id) |
|||
{ |
|||
var materialOutfit = await _context.MaterialOutfits.FindAsync(id); |
|||
if (materialOutfit == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
_context.MaterialOutfits.Remove(materialOutfit); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return materialOutfit; |
|||
} |
|||
|
|||
private bool MaterialOutfitExists(int id) |
|||
{ |
|||
return _context.MaterialOutfits.Any(e => e.MaterialOutfitID == id); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,126 @@ |
|||
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; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|||
{ |
|||
/// <summary>
|
|||
/// 料號站別工項資料檔
|
|||
/// </summary>
|
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class MaterialStationsItemController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
public MaterialStationsItemController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
// GET: api/MaterialStationsItems
|
|||
[HttpGet] |
|||
public async Task<ActionResult<IEnumerable<MaterialStationsItem>>> GetMaterialStationsItems() |
|||
{ |
|||
return await _context.MaterialStationsItems.ToListAsync(); |
|||
} |
|||
|
|||
// GET: api/MaterialStationsItems/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<MaterialStationsItem>> GetMaterialStationsItem(int id) |
|||
{ |
|||
var materialStationsItem = await _context.MaterialStationsItems.FindAsync(id); |
|||
|
|||
if (materialStationsItem == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return materialStationsItem; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 料號站別工項資料檔 by ItemID
|
|||
/// </summary>
|
|||
/// <param name="id">ItemID</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("ByItemID/{id}")] |
|||
public async Task<IEnumerable<MaterialStationsItem>> GetMaterialStationsItemByItemID(int id) |
|||
{ |
|||
IQueryable<MaterialStationsItem> q = _context.MaterialStationsItems; |
|||
var result = await q.Where(p => p.ItemID == id).ToListAsync(); |
|||
return result; |
|||
} |
|||
|
|||
// PUT: api/MaterialStationsItems/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<IActionResult> PutMaterialStationsItem(int id, MaterialStationsItem materialStationsItem) |
|||
{ |
|||
if (id != materialStationsItem.MsiID) |
|||
{ |
|||
return BadRequest(); |
|||
} |
|||
|
|||
_context.Entry(materialStationsItem).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateConcurrencyException) |
|||
{ |
|||
if (!MaterialStationsItemExists(id)) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
return NoContent(); |
|||
} |
|||
|
|||
// POST: api/MaterialStationsItems
|
|||
// 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<ActionResult<MaterialStationsItem>> PostMaterialStationsItem(MaterialStationsItem materialStationsItem) |
|||
{ |
|||
_context.MaterialStationsItems.Add(materialStationsItem); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return CreatedAtAction("GetMaterialStationsItem", new { id = materialStationsItem.MsiID }, materialStationsItem); |
|||
} |
|||
|
|||
// DELETE: api/MaterialStationsItems/5
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ActionResult<MaterialStationsItem>> DeleteMaterialStationsItem(int id) |
|||
{ |
|||
var materialStationsItem = await _context.MaterialStationsItems.FindAsync(id); |
|||
if (materialStationsItem == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
_context.MaterialStationsItems.Remove(materialStationsItem); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return materialStationsItem; |
|||
} |
|||
|
|||
private bool MaterialStationsItemExists(int id) |
|||
{ |
|||
return _context.MaterialStationsItems.Any(e => e.MsiID == id); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue