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 BoxChangesController : ControllerBase { private readonly AMESContext _context; /// <summary> /// /// </summary> /// <param name="context"></param> public BoxChangesController(AMESContext context) { _context = context; } /// <summary> /// /// </summary> /// <returns></returns> // GET: api/BoxChanges [HttpGet] public async Task<ActionResult<IEnumerable<BoxChange>>> GetBoxChange() { return await _context.BoxChanges.ToListAsync(); } /// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> // GET: api/BoxChanges/5 [HttpGet("{id}")] public async Task<ActionResult<BoxChange>> GetBoxChange(int id) { var boxChange = await _context.BoxChanges.FindAsync(id); if (boxChange == null) { return NotFound(); } return boxChange; } /// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="boxChange"></param> /// <returns></returns> // PUT: api/BoxChanges/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> PutBoxChange(int id, BoxChange boxChange) { if (id != boxChange.BoxChangeID) { return BadRequest(); } _context.Entry(boxChange).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoxChangeExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } /// <summary> /// /// </summary> /// <param name="boxChange"></param> /// <returns></returns> // POST: api/BoxChanges // 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<BoxChange>> PostBoxChange(BoxChange boxChange) { _context.BoxChanges.Add(boxChange); await _context.SaveChangesAsync(); return CreatedAtAction("GetBoxChange", new { id = boxChange.BoxChangeID }, boxChange); } /// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> // DELETE: api/BoxChanges/5 [HttpDelete("{id}")] public async Task<ActionResult<BoxChange>> DeleteBoxChange(int id) { var boxChange = await _context.BoxChanges.FindAsync(id); if (boxChange == null) { return NotFound(); } _context.BoxChanges.Remove(boxChange); await _context.SaveChangesAsync(); return boxChange; } private bool BoxChangeExists(int id) { return _context.BoxChanges.Any(e => e.BoxChangeID == id); } } }