public async Task <IActionResult> Post([FromBody] OverheadLine overheadLine) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.OverheadLines.Add(overheadLine); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (OvHeadExists(overheadLine.ID)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("Get", new { id = overheadLine.ID }, overheadLine)); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] OverheadLine overheadLine) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != overheadLine.ID) { return(BadRequest()); } _context.Entry(overheadLine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OvHeadExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Delete([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } OverheadLine overheadLine = await _context.OverheadLines.SingleOrDefaultAsync(m => m.ID == id); if (overheadLine == null) { return(NotFound()); } _context.OverheadLines.Remove(overheadLine); await _context.SaveChangesAsync(); return(Ok(overheadLine)); }