Ejemplo n.º 1
0
 public static Bid MapAsNewEntity(this CreateBidResource model, Auction.Api.Data.Entities.Auction auction)
 {
     return(new Bid
     {
         Value = model.Value,
         Auction = auction,
         Winner = model.Winner
     });
 }
        public async Task <ActionResult <BidResource> > Post(int auctionId, CreateBidResource 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.cache.Remove("AllBidsAuction" + auctionId);

            var entity = model.MapAsNewEntity(auction);

            this.context.Bids.Add(entity);
            await this.context.SaveChangesAsync(cancellationToken);

            return(this.CreatedAtAction("Get", new { auctionId, id = entity.Id }, entity.MapAsResource()));
        }