Beispiel #1
0
        public void CreateBidTest_CreateBidAtNotActiveAuction_BLValidationExceptionThrown()
        {
            //arrange
            var bid = new BidDTO()
            {
                Id       = 6,
                BidDate  = DateTime.Now,
                UserName = "******",
                LotId    = 1,
                BidPrice = 20
            };

            _mockUnitOfWork.Setup(x => x.Lots.GetById(bid.LotId)).Returns(new Lot()
            {
                Id           = 1,
                BeginDate    = DateTime.Now.AddDays(-10),
                EndDate      = DateTime.Now.AddDays(-5),
                InitialPrice = 1,
                Bids         = new List <Bid>()
            });

            //act

            //assert
            Assert.Throws <BLValidationException>(() => _service.CreateBid(bid), "Bid can’t be placed after auction end");
        }
Beispiel #2
0
        public async Task CreateBidAsync(string bidAmount, string consoleId)
        {
            if (bidAmount == null || consoleId == null)
            {
                return;
            }

            var isParsed = decimal.TryParse(bidAmount, out var parsedBidAmount);

            if (!isParsed)
            {
                return;
            }

            var item = _itemsService.GetById(consoleId);

            if (item == null)
            {
                return;
            }

            if (item.Price >= parsedBidAmount)
            {
                return;
            }

            var userId       = Context.UserIdentifier;
            var serviceModel = new BidCreateServiceModel
            {
                Amount = parsedBidAmount,
                MadeOn = DateTime.UtcNow,
                ItemId = item.Id,
                UserId = userId
            };

            var succeeded = _bidService.CreateBid(serviceModel);

            if (!succeeded)
            {
                return;
            }

            await Clients.Groups(consoleId).SendAsync("ReceivedMessage", parsedBidAmount, userId);
        }
 public ActionResult MakeBid(MakeBidViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var lot = _lotService.GetLotEntity(viewModel.Id);
         if (lot.EndDate > DateTime.Now && viewModel.MakeBid > viewModel.CurrentBid)
         {
             _bidService.CreateBid(new BidEntity()
             {
                 BidAmount = viewModel.MakeBid,
                 BidTime   = DateTime.Now,
                 LotRefId  = viewModel.Id,
                 UserRefId = _userService.GetUserEntityByLogin(User.Identity.Name).Id
             });
         }
         return(RedirectToAction("LotDetails", new { id = viewModel.Id }));
     }
     return(RedirectToAction("LotDetails", new { id = viewModel.Id }));
 }
Beispiel #4
0
        public ActionResult CreateBid([FromBody] BidDTO bid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BidDTO created;

            try
            {
                created = _bidService.CreateBid(bid);
            }
            catch (Exception ex)
            {
                return(BadRequest("Validation error. " + ex.Message));
            }
            return(CreatedAtAction(nameof(GetBid), new { id = created.Id }, created));
        }