public async Task <IActionResult> Put(int auctionId, int id, UpdateItemResource model, CancellationToken cancellationToken) { var auction = await this.context.Auctions.FindAsync(auctionId); if (auction == null) { this.dumbLogger.LogInfo($"Auction {auctionId} not found."); return(new BadRequestObjectResult(new Exception($"Auction {auctionId} not found."))); //return this.NotFound(); } var item = await this.context.Items.FindAsync(id); if (item == null) { this.dumbLogger.LogInfo($"Item {id} not found."); return(this.NotFound()); } if (item.Auction == null || item.Auction.Id != auctionId) { this.dumbLogger.LogInfo($"Item {id} not found for auction {auctionId}."); return(this.NotFound()); } this.cache.Remove("AllItemsAuction" + auctionId); item.UpdateWith(model); this.context.Items.Update(item); await this.context.SaveChangesAsync(cancellationToken); return(this.NoContent()); }
public static void UpdateWith(this Item item, UpdateItemResource model) { item.Name = model.Name; item.MinPrice = model.MinPrice; }