public async Task <IActionResult> PutKite(int id, KiteDto kiteDto) { if (id != kiteDto.KiteId) { return(BadRequest()); } var kite = await _context.Kites.FindAsync(id); if (kite == null) { return(NotFound()); } kite.UpdateDetails(kiteDto.Size, kiteDto.PrincipalColor, kiteDto.PurchaseDate); kite.UpdateKiteModel(kiteDto.KiteModelId); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!KiteExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <KiteDto> > PostKite(KiteDto kiteDto) { var kite = new Kite(kiteDto.Size, kiteDto.PrincipalColor, kiteDto.PurchaseDate, kiteDto.KiteModelId); _context.Kites.Add(kite); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetKite), new { id = kiteDto.KiteId }, KiteToDto(kite))); }