public async Task <IActionResult> PutLocalItem(long id, LocalItemDto localItemDto) { if (id != localItemDto.Id) { return(BadRequest()); } var localItem = _context.LocalItems.First(li => li.Id == localItemDto.Id); localItem.Item = _context.Items.First(i => i.Id == localItemDto.ItemId); localItem.Outpost = _context.Outposts.First(o => o.Id == localItemDto.OutpostId); _context.Entry(localItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocalItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <LocalItemDto> > PostLocalItem(LocalItemDto localItemDto) { _context.LocalItems.Add(new LocalItem { Item = _context.Items.First(i => i.Id == localItemDto.ItemId), Outpost = _context.Outposts.First(o => o.Id == localItemDto.OutpostId) }); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLocalItem", new { id = localItemDto.Id }, localItemDto)); }