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.

114 lines
3.0 KiB

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>
/// 工單KP資訊資料檔
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class WipKpsController : ControllerBase
{
private readonly AMESContext _context;
public WipKpsController(AMESContext context)
{
_context = context;
}
// GET: api/WipKps
[HttpGet]
public async Task<ActionResult<IEnumerable<WipKp>>> GetWipKps()
{
return await _context.WipKps.ToListAsync();
}
// GET: api/WipKps/5
[HttpGet("{id}")]
public async Task<ActionResult<WipKp>> GetWipKp(int id)
{
var wipKp = await _context.WipKps.FindAsync(id);
if (wipKp == null)
{
return NotFound();
}
return wipKp;
}
// PUT: api/WipKps/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> PutWipKp(int id, WipKp wipKp)
{
if (id != wipKp.WipKpID)
{
return BadRequest();
}
_context.Entry(wipKp).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!WipKpExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/WipKps
// 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<WipKp>> PostWipKp(WipKp wipKp)
{
_context.WipKps.Add(wipKp);
await _context.SaveChangesAsync();
return CreatedAtAction("GetWipKp", new { id = wipKp.WipKpID }, wipKp);
}
// DELETE: api/WipKps/5
[HttpDelete("{id}")]
public async Task<ActionResult<WipKp>> DeleteWipKp(int id)
{
var wipKp = await _context.WipKps.FindAsync(id);
if (wipKp == null)
{
return NotFound();
}
_context.WipKps.Remove(wipKp);
await _context.SaveChangesAsync();
return wipKp;
}
private bool WipKpExists(int id)
{
return _context.WipKps.Any(e => e.WipKpID == id);
}
}
}