public static Item MapAsNewEntity(this CreateItemResource model, Auction.Api.Data.Entities.Auction auction) { return(new Item { Name = model.Name, Auction = auction, MinPrice = model.MinPrice }); }
public async Task <ActionResult <ItemResource> > Post(int auctionId, CreateItemResource 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."))); //this.NotFound(); } this.cache.Remove("AllItemsAuction" + auctionId); var entity = model.MapAsNewEntity(auction); this.context.Items.Add(entity); await this.context.SaveChangesAsync(cancellationToken); return(this.CreatedAtAction("Get", new { auctionId, id = entity.Id }, entity.MapAsResource())); }