public async Task <IActionResult> AddEquipmentDetails([FromBody] InputEquipmentDetails input) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(input)); } var type = await _context.EquipmentTypes.FindAsync(input.TypeId); if (type == null) { return(NotFound()); } var details = input.ToModel(); await _context.EquipmentDetails.AddAsync(details); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetDetails), new { id = details.Id }, await _detailsHandler.OutputFor(details) )); }
public async Task <IActionResult> UpdateDetails(int id, [FromBody] InputEquipmentDetails input) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(input)); } var current = await _context.EquipmentDetails.FindAsync(id); if (current == null) { return(NotFound()); } var updated = input.ToModel(); current.Name = updated.Name; current.Price = updated.Price; current.TypeId = updated.TypeId; await _context.SaveChangesAsync(); return(Ok(await _detailsHandler.OutputFor(current))); }