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.
138 lines
4.2 KiB
138 lines
4.2 KiB
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);
|
|
}
|
|
}
|
|
}
|
|
|