Exemplo n.º 1
0
            public async Task <Unit> Handle(SetAutoBiddingCommand request, CancellationToken cancellationToken)
            {
                var userBid = await _userBidService.GetByIdAsync(request.UserId);

                if (userBid == null)
                {
                    throw new Exception("Please set max bid");
                }

                var currentActive = await _bidService.GetTotalAmountOngoingBidByUserId(request.UserId);

                if (userBid.MaxAmount > currentActive)
                {
                    var bid = await _bidService.GetActiveBidIdAsync(request.ProductId);

                    if (bid.HasValue)
                    {
                        var autoBid = await _dbContext.AutoBids.Where(x => x.BidId == bid.Value && x.UserId == request.UserId).FirstOrDefaultAsync();

                        if (autoBid == null)
                        {
                            autoBid = new Entities.AutoBid(request.UserId, bid.Value);
                            _dbContext.AutoBids.Add(autoBid);
                        }
                        else
                        {
                            autoBid.IsActive = true;
                        }
                    }
                    else
                    {
                        throw new Exception("Please set max bid");
                    }
                }
                else
                {
                    throw new Exception("Your current bid exceed maximum");
                }

                await _dbContext.SaveChangesAsync();

                return(Unit.Value);
            }
Exemplo n.º 2
0
            public async Task <Unit> Handle(SetMaxBidCommand request, CancellationToken cancellationToken)
            {
                var userBid = await _userBidService.GetByIdAsync(request.UserId);

                if (userBid == null)
                {
                    userBid           = new UserBid();
                    userBid.UserId    = request.UserId;
                    userBid.MaxAmount = request.Amount;
                    _dbContext.UserBids.Add(userBid);
                }
                else
                {
                    userBid.MaxAmount = request.Amount;
                }

                await _dbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }