public async Task <bool> DeleteAsync(AuctionDeleteRequestModel request, int loggedInUserId)
        {
            var strategy = m_context.Database.CreateExecutionStrategy();
            await strategy.Execute(async() =>
            {
                try
                {
                    using (var transaction = m_context.Database.BeginTransaction())
                    {
                        foreach (int auctionId in request.AuctionIds)
                        {
                            bool auctionExists = await m_context.Auctions.AnyAsync(auct => auct.AuctionId == auctionId).ConfigureAwait(true);

                            if (auctionExists)
                            {
                                Auction auctionForDelete = await m_context.Auctions
                                                           .Where(auct => auct.AuctionId == auctionId)
                                                           .FirstOrDefaultAsync()
                                                           .ConfigureAwait(true);

                                if (auctionForDelete.AuctionImageContainer.IsSpecified())
                                {
                                    await HandleAuctionDeleteImages(auctionForDelete.AuctionImageContainer).ConfigureAwait(true);
                                }

                                AuctionItem auctionItemDetails = await m_context.AuctionItems
                                                                 .Where(aitem => aitem.AuctionId == auctionId)
                                                                 .FirstOrDefaultAsync()
                                                                 .ConfigureAwait(true);

                                AuctionDetails auctionDetails = await m_context.AuctionDetails
                                                                .Where(adet => adet.AuctionItemId == auctionItemDetails.AuctionItemId)
                                                                .FirstOrDefaultAsync()
                                                                .ConfigureAwait(true);

                                m_context.Remove(auctionDetails);
                                m_context.Remove(auctionItemDetails);
                                m_context.Remove(auctionForDelete);

                                await m_context.SaveChangesAsync().ConfigureAwait(true);
                            }
                            else
                            {
                                throw new WebApiException(HttpStatusCode.BadRequest, AuctionErrorMessages.NotActiveAuction);
                            }
                        }

                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    throw new WebApiException(HttpStatusCode.BadRequest, AuctionErrorMessages.CouldNotDeleteAuction, ex);
                }
            }).ConfigureAwait(true);

            return(true);
        }
Exemple #2
0
        public async Task <BiddingProperty> AddBiddingProperty(BiddingProperty property)
        {
            var biddingProperty = new BiddingProperty()
            {
                Title           = property.Title,
                AskingPrice     = property.AskingPrice,
                IsBiddingActive = true
            };

            _context.BiddingProperties.Add(biddingProperty);
            await _context.SaveChangesAsync();

            return(biddingProperty);
        }
        public async Task <ActionResult <Auction> > Bidding([FromBody] Auction auction)
        {
            if (!Request.Headers.ContainsKey("Authorization"))
            {
                return(BadRequest(new { message = "You shall not pass" }));
            }
            Bid bid = Convert(auction);

            //Auction result = new Auction() { MinimumAmount = auction.MinimumAmount + 1000, auctionBundleId = 1000 };
            _context.Bid.Add(bid);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBid", new { id = auction.Id }, bid));

            /*
             * if (result == null)
             * {
             *  return NotFound();
             * }
             *
             * return new ObjectResult(result);
             */
        }