public async Task <Event> Withdraw(WithdrawHistory obj) { var bidderId = (await _bllUsers.GetByUsernameAsync(obj.Username)).Id; var objEvent = await _bllEvents.GetAsync(obj.EventId); var latestBid = await _bllBidHistories.GetLatestUserBid(bidderId, obj.AuctionId, obj.EventId); //if latest bidder isn't our bidder (or if there are no bids yet), no need to use our processor any further and cause some unknown catastrophic error. if (latestBid == null || bidderId != latestBid.UserId) { return(null); } var throwbackBidHistory = await _bllWithdraws.GetThrowbackAsync(new BO.WithdrawHistory() { UserId = bidderId, AuctionId = obj.AuctionId, EventId = obj.EventId }); if (throwbackBidHistory.UserId == 0 || throwbackBidHistory.BidAmount > objEvent.CurrentPrice) { return(null); } //update throwback details ( topBidder and currentPrice for throwback bidder ) of event. var updatedEvent = new BO.Event() { CurrentPrice = throwbackBidHistory.BidAmount, TopBidder = throwbackBidHistory.UserId, Id = objEvent.Id, ItemId = objEvent.ItemId, AuctionId = objEvent.AuctionId, StartDate = objEvent.StartDate, EndDate = objEvent.EndDate, Lun = objEvent.Lun, Lud = objEvent.Lud, MinPriceIncrementAmount = objEvent.MinPriceIncrementAmount }; //Register withdraw history var successWithdraw = await _bllWithdraws.AddAsync(new BO.WithdrawHistory() { AuctionId = obj.AuctionId, EventId = obj.EventId, UserId = bidderId, WithdrawAmount = latestBid.BidAmount, WithdrawDate = DateTime.Now }); var successEvent = await _bllEvents.UpdateAsync(updatedEvent); return(Mapper.Event(updatedEvent)); }
public static Event Event(BO.Event obj) { return(new Event() { Id = obj.Id, ItemId = obj.ItemId, AuctionId = obj.AuctionId, StartDate = obj.StartDate, EndDate = obj.EndDate, CurrentPrice = obj.CurrentPrice, TopBidder = obj.TopBidder, MinPriceIncrementAmount = obj.MinPriceIncrementAmount, Lun = obj.Lun, Lud = obj.Lud }); }