public void GivenTwoAuctionsWhenGetAllAuctionsThenBothAuctionsReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem1 = new AuctionItemBuilder()
                               .WithMinAmount("100")
                               .Build();

            //new AuctionItemViewModel
            //{
            //    Description = "Description",
            //    MinAmount = "100",
            //    Name = "Auction item"
            //};
            var auctionItem2 = new AuctionItemViewModel {
                Description = "Description 2",
                MinAmount   = "100",
                Name        = "Auction item 2"
            };

            _auctionService.CreateAuction(username, auctionItem1);
            _auctionService.CreateAuction(username, auctionItem2);


            // Act
            var auctions = _auctionService.GetAllAuctions();

            // Assert
            Assert.IsNotEmpty(auctions);
            Assert.AreEqual(2, auctions.Count());
        }
Example #2
0
 public static AuctionItem ToAuctionItem(this AuctionItemViewModel viewModel)
 {
     return(new AuctionItem
     {
         Name = viewModel.Name,
         Description = viewModel.Description
     });
 }
        public IActionResult Get(int id)
        {
            AuctionItemViewModel auctionItem = service.GetAuctionItemById(id);

            if (auctionItem == null)
            {
                return(NotFound());
            }
            return(Ok(auctionItem));
        }
        public IActionResult GetItem(int auctionid)
        {
            if (Logged_user == null)
            {
                return(RedirectToAction(""));
            }

            try
            {
                Auction tryAuction = _context.auctions.Where(a => a.id == auctionid).SingleOrDefault();
            }
            catch (System.Exception)
            {
                return(RedirectToAction(""));
            }

            Auction theAuction = _context.auctions.Where(a => a.id == auctionid).SingleOrDefault();

            HttpContext.Session.SetInt32("AuctionId", auctionid);

            List <Bid> allBids = _context.bids.Where(b => b.auctionid == auctionid).OrderByDescending(b => b.amount).ToList();

            Bid  highBid    = new Bid();
            User highBidder = new User();

            if (allBids.Count() == 0)
            {
                highBid.id            = 0;
                highBid.userid        = 0;
                highBid.auctionid     = auctionid;
                highBid.amount        = 0;
                highBid.created_at    = DateTime.Now;
                highBidder.id         = 0;
                highBidder.first_name = "... Nobody has bid yet";
                highBidder.created_at = DateTime.Now;

                Console.WriteLine("=================== BID is NULL ===============================================");
            }
            else
            {
                highBid    = allBids.First();
                highBidder = _context.users.SingleOrDefault(u => u.id == highBid.userid);
            }

            AuctionItemViewModel ViewModel = new AuctionItemViewModel()
            {
                Current_user        = Logged_user,
                Current_auction     = theAuction,
                Current_bid         = highBid,
                Current_high_bidder = highBidder,
                Current_creator     = _context.users.SingleOrDefault(u => u.id == theAuction.creatorid),
            };

            return(View("AuctionItem", ViewModel));
        }
 public IActionResult Put(int id, [FromBody] AuctionItemViewModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (!service.UpdateAuctionItem(id, value))
     {
         return(NotFound());
     }
     return(NoContent());
 }
Example #6
0
        public async Task CreateAuctionItem(AuctionItemViewModel itemViewModel)
        {
            var item = _mapper.Map <AuctionItemViewModel, AuctionItem>(itemViewModel);

            if (string.IsNullOrWhiteSpace(item.Id))
            {
                item.Id = Guid.NewGuid().ToString();
            }

            await _auctionItemRepository.Create(item);

            ScheduleAuctionEndEvent(item);
        }
Example #7
0
        private static AuctionViewModel CreateNewAuctionViewModel(string username, AuctionItemViewModel auctionItemViewModel, int auctionState)
        {
            var newAuction = new AuctionViewModel
            {
                AuctionItem  = auctionItemViewModel,
                MinAmount    = auctionItemViewModel.MinAmount,
                Seller       = username,
                AuctionState = auctionState,
                StartDate    = DateTime.Today.AddMinutes(1),
                EndDate      = DateTime.Today.AddDays(7)
            };

            return(newAuction);
        }
Example #8
0
        public async Task Should_Create_Auction_Item()
        {
            var item = new AuctionItemViewModel()
            {
                Name        = "TEST_ITEM",
                Description = "TEST_Description"
            };

            await _itemService.CreateAuctionItem(item);

            await _mockAuctionItemRepository.Received(1).Create(Arg.Is <AuctionItem>(x => !string.IsNullOrEmpty(x.Id)));

            _mockJobService.Received(1).PublishDelayedEvent(Arg.Is <Event <AuctionEndEventData> >(e => !string.IsNullOrEmpty(e.Data.ItemId)), Arg.Any <TimeSpan>());
        }
        public async Task <AuctionItemViewModel> GetItem(int id)
        {
            AuctionItemDto auctionItemDto = null;

            HttpResponseMessage response = await _httpClient.GetAsync($"api/auction/{id}");

            if (response.IsSuccessStatusCode)
            {
                auctionItemDto = await response.Content.ReadAsAsync <AuctionItemDto>();
            }

            AuctionItemViewModel auctionItemViewModel = Adapt(auctionItemDto);

            return(auctionItemViewModel);
        }
        public AuctionItemViewModel GetAuctionItemById(int id)
        {
            AuctionItemViewModel auctionItem = repo.List <AuctionItem>()
                                               .Where(x => x.Id == id)
                                               .Select(x => new AuctionItemViewModel()
            {
                Id           = x.Id,
                Name         = x.Name,
                Description  = x.Description,
                MinimumBid   = x.MinimumBid,
                NumberOfBids = x.NumberOfBids,
                ImageUrl     = x.ImageUrl,
            })
                                               .FirstOrDefault();

            return(auctionItem);
        }
        public bool UpdateAuctionItem(int id, AuctionItemViewModel AuctionItem)
        {
            var record = GetAuctionItemById(id);

            if (record == null)
            {
                return(false);
            }
            record.Name         = AuctionItem.Name;
            record.Description  = AuctionItem.Description;
            record.MinimumBid   = AuctionItem.MinimumBid;
            record.NumberOfBids = AuctionItem.NumberOfBids;
            record.ImageUrl     = AuctionItem.ImageUrl;
            record.Users        = AuctionItem.Users;
            repo.Update <AuctionItemViewModel>(record);
            return(true);
        }
        public void GivenOneAuctionWhenGetByInvalidUsernameThenEmptyListReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem1 = new AuctionItemViewModel
            {
                Description = "Description",
                MinAmount   = "100",
                Name        = "Auction item"
            };;

            // Act
            var newAUction        = _auctionService.CreateAuction(username, auctionItem1);
            var retrievedAuctions = _auctionService.GetAuctionsByUsername("another username");

            // Assert
            Assert.IsEmpty(retrievedAuctions);
        }
        public void GivenOneOpenAuctionWhenCloseAuctionThenAuctionIsClosed()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem = new AuctionItemViewModel
            {
                Description = "Description",
                MinAmount   = "100",
                Name        = "Auction item"
            };

            // Act
            var newAuction    = _auctionService.CreateAuction(username, auctionItem);
            var closedAuction = _auctionService.CloseAuction(newAuction);

            // Assert
            Assert.AreEqual(newAuction.AuctionId, closedAuction.AuctionId);
            Assert.AreEqual(2, closedAuction.AuctionState);
        }
        public ActionResult Create(AuctionItemViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMessage = "All fields are required.";
                return(View(viewModel));
            }

            float minAmount;

            if (!float.TryParse(viewModel.MinAmount, out minAmount))
            {
                ViewBag.ErrorMessage = "Wrong format for minimum amount. Please input the correct number.";
                return(View());
            }

            _auctionService.CreateAuction(UserSession.CurrentUser.Username, viewModel);
            return(RedirectToAction("Index"));
        }
Example #15
0
 public AuctionBuilder()
 {
     auctionId  = 1;
     userAmount = "123";
     startDate  = DateTime.Now;
     seller     = "stefan";
     minAmount  = "100";
     endDate    = DateTime.Now.AddSeconds(1);
     bids       = new List <float> {
         100, 120, 121, 122, 123
     };
     bidAmount    = "123";
     auctionState = 1;
     auctionItem  = new AuctionItemViewModel
     {
         Description = "some description",
         MinAmount   = "123",
         Name        = "auction item"
     };
 }
        public void GivenTwoPendingAuctionsWhenGetOpenAuctionsThenEmptyListReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem1 = new AuctionItemViewModel
            {
                Description = "Description",
                MinAmount   = "100",
                Name        = "Auction item"
            };;

            // Act
            var pendingAuction  = _auctionService.CreateAuction(username, auctionItem1, 0);
            var pendingAuction1 = _auctionService.CreateAuction(username, auctionItem1, 0);

            var retrievedAuctions = _auctionService.GetOpenAuctions();

            // Assert
            Assert.IsEmpty(retrievedAuctions);
        }
        public void GivenNewAuctionWhenGetsByValidUsernameThenNewAuctionIsReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem1 = new AuctionItemViewModel
            {
                Description = "Description",
                MinAmount   = "100",
                Name        = "Auction item"
            };

            // Act
            var newAUction        = _auctionService.CreateAuction(username, auctionItem1);
            var retrievedAuctions = _auctionService.GetAuctionsByUsername(username);

            // Assert
            Assert.IsNotEmpty(retrievedAuctions);
            Assert.AreEqual(newAUction.AuctionId, retrievedAuctions.FirstOrDefault().AuctionId);
            Assert.AreEqual(newAUction.Seller, retrievedAuctions.FirstOrDefault().Seller);
        }
Example #18
0
        public async Task <IActionResult> Edit(int id, string status, string callBack)
        {
            if (status != SD.UpcomingStatus)
            {
                return(NotFound());
            }

            var auction = await _db.AuctionHeader.Include(a => a.User).Where(a => a.Id == id).FirstOrDefaultAsync();

            var products = await _db.AuctionProduct.Include(a => a.Product).Where(a => a.AuctionId == id).ToListAsync();

            var vm = new AuctionItemViewModel()
            {
                AuctionHeader  = auction,
                AuctionProduct = products,
                Status         = status,
                CallBack       = callBack
            };

            return(View(vm));
        }
Example #19
0
        public AuctionViewModel CreateAuction(string username, AuctionItemViewModel auctionItemViewModel, int auctionState = 1)
        {
            if (auctionItemViewModel == null)
            {
                throw new ArgumentNullException($"AuctionItemViewModel must be provided");
            }

            var user = GetUser(username);

            if (user == null)
            {
                throw new ArgumentException($"User {username} doesn't exist");
            }

            var newAuction = CreateNewAuctionViewModel(username, auctionItemViewModel, auctionState);
            var auction    = _auctionRepository.CreateAuction(newAuction.ToAuction(user));

            _auditRepository.CreateRecord(username, auction.AuctionId.ToString(), "Auction created");

            return(auction.ToAuctionViewModel());
        }
Example #20
0
        public ActionResult SaveSellerItemStatus(AuctionItemViewModel itemViewModel, FormCollection form)
        {
            string valueOf = form["auctionItem.SellerSent"].ToString();

            ABUser seller = _auctionService.ViewSellerAuctionIdViaEmail(UserInfoModel.Email);


            if (valueOf.Equals("1"))
            {
                itemViewModel.auctionItem.SellerSent = true;
            }
            else if (valueOf.Equals("0"))
            {
                itemViewModel.auctionItem.SellerSent = false;
            }
            else
            {
            }


            Auction queryObj;

            try
            {
                queryObj            = _auctionService.ViewAuctionByGUID(seller.ABUser_AuctionGUID.Value);
                queryObj.SellerSent = itemViewModel.auctionItem.SellerSent;
            }
            catch
            {
                return(null);
            }

            ServiceResult result = _auctionService.SaveSellerShippingStatus(queryObj);

            if (result.Success)
            {
                return(RedirectToAction("Item", result));
            }
            return(null);
        }
        public void GivenOneOpenAndTwoClosedAuctionsWhenGetOpenAuctionsThenOneAuctionIsReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);

            var auctionItem1 = new AuctionItemViewModel {
                Description = "Description",
                MinAmount   = "100",
                Name        = "Auction item"
            };

            // Act
            var openedAuction  = _auctionService.CreateAuction(username, auctionItem1);
            var closedAuction  = _auctionService.CreateAuction(username, auctionItem1, 2);
            var closedAuction1 = _auctionService.CreateAuction(username, auctionItem1, 2);

            var retrievedAuctions = _auctionService.GetOpenAuctions();

            // Assert
            Assert.IsNotEmpty(retrievedAuctions);
            Assert.AreEqual(1, retrievedAuctions.Count());
            Assert.AreEqual(openedAuction.AuctionId, retrievedAuctions.FirstOrDefault().AuctionId);
        }
Example #22
0
        public async Task <IActionResult> Edit(AuctionItemViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var auction = await _db.AuctionHeader.Where(a => a.Id == vm.AuctionHeader.Id).FirstOrDefaultAsync();

                auction.EndDate      = vm.AuctionHeader.EndDate;
                auction.CurrentPrice = vm.AuctionHeader.CurrentPrice;
                auction.PriceStep    = vm.AuctionHeader.PriceStep;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Details", new{ id = auction.Id, status = vm.Status, callBack = vm.CallBack }));
            }
            foreach (var modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    Console.WriteLine(error.ErrorMessage);
                }
            }

            return(RedirectToAction("Details", new{ id = vm.AuctionHeader.Id, status = vm.Status, callBack = vm.CallBack }));
        }
Example #23
0
        public async Task <IActionResult> Details(int id, string status, string callBack)
        {
            var auction = await _db.AuctionHeader.Where(a => a.Id == id).Include(a => a.User).FirstOrDefaultAsync();

            if (auction == null)
            {
                return(NotFound());
            }

            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var vm = new AuctionItemViewModel();

            vm.AuctionHeader = auction;

            vm.AuctionProduct = await _db.AuctionProduct.Where(a => a.AuctionId == auction.Id).Include(a => a.Product).ToListAsync();

            var a_user = await _db.AuctionUser.Where(a => a.UserId == claim.Value && a.AuctionId == id).FirstOrDefaultAsync();

            if (a_user != null)
            {
                ViewBag.Bid = true;
            }
            else
            {
                ViewBag.Bid = false;
            }

            vm.AuctionUser = await _db.AuctionUser.FirstOrDefaultAsync(a => a.UserId == claim.Value && a.AuctionId == id);

            vm.Status   = status;
            vm.CallBack = callBack;
            vm.IsSelf   = claim.Value == auction.User.Id;

            return(View(vm));
        }
Example #24
0
 public AuctionBuilder WithAuctionItem(AuctionItemViewModel auctionItem)
 {
     this.auctionItem = auctionItem;
     return(this);
 }
Example #25
0
        public async Task <IActionResult> Auctions(string id, string callBack, string status)
        {
            var user = await _db.User.Where(u => u.Id == id).FirstOrDefaultAsync();

            if (user == null)
            {
                return(NotFound());
            }

            var vm = new AuctionStatusViewModel();

            vm.UserId   = user.Id;
            vm.CallBack = callBack;
            vm.Status   = status;
            var auctions = new List <AuctionHeader>();

            if (callBack == SD.CreatedAuctions)
            {
                auctions = await _db.AuctionHeader.Include(a => a.User).Where(a => a.SellerId == user.Id).ToListAsync();
            }
            else
            {
                var aUsers = await _db.AuctionUser.Where(u => u.UserId == user.Id).ToListAsync();

                foreach (var a in aUsers)
                {
                    var auction = await _db.AuctionHeader.Include(au => au.User).Where(au => au.Id == a.AuctionId).FirstOrDefaultAsync();

                    auctions.Add(auction);
                }
            }

            var currentDate = DateTime.Now;

            foreach (var item in auctions)
            {
                var products = await _db.AuctionProduct.Include(a => a.Product).Where(a => a.AuctionId == item.Id).ToListAsync();

                var itemVM = new AuctionItemViewModel()
                {
                    AuctionHeader  = item,
                    AuctionProduct = products,
                    CallBack       = callBack
                };
                itemVM.AuctionUser = await _db.AuctionUser.Include(u => u.User).Where(u => u.AuctionId == item.Id && u.UserId == user.Id).FirstOrDefaultAsync();

                if (currentDate < item.BeginDate && status == SD.UpcomingStatus)
                {
                    vm.Auctions.Add(itemVM);
                }
                if (currentDate >= item.BeginDate && currentDate <= item.EndDate && status == SD.ActiveStatus)
                {
                    vm.Auctions.Add(itemVM);
                }
                if (currentDate > item.EndDate && status == SD.PastStatus)
                {
                    vm.Auctions.Add(itemVM);
                }
            }
            return(View(vm));
        }
Example #26
0
        public ActionResult Item()
        {
            AuctionItemViewModel result = _auctionService.ViewSellerAuction(UserInfoModel.Email);

            return(View(result));
        }
Example #27
0
        public async Task <IActionResult> Index(string callBack, string status)
        {
            if (!User.Identity.IsAuthenticated && callBack != SD.AllAuctions)
            {
                return(NotFound());
            }

            if (User.IsInRole(SD.CustomerUser) && callBack == SD.CreatedAuctions)
            {
                return(NotFound());
            }

            var currentDate    = DateTime.Now;
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var auItems = new AuctionStatusViewModel();

            auItems.CallBack = callBack;
            auItems.Status   = status;
            var auctions = await _db.AuctionHeader.Include(a => a.User).ToListAsync();

            if (callBack == SD.BidedAuctions)
            {
                var newAuctions   = new List <AuctionHeader>();
                var user_auctions = await _db.AuctionUser.Where(a => a.UserId == claim.Value).ToListAsync();

                foreach (var a in auctions)
                {
                    if (UserParticipate(a.Id, user_auctions))
                    {
                        newAuctions.Add(a);
                    }
                }
                auctions = newAuctions;
            }
            if (callBack == SD.CreatedAuctions)
            {
                auctions = await _db.AuctionHeader.Where(a => a.SellerId == claim.Value).Include(a => a.User).ToListAsync();
            }

            var filterAuctions = new List <AuctionItemViewModel>();

            foreach (var a in auctions)
            {
                var item = new AuctionItemViewModel();
                item.AuctionHeader  = a;
                item.AuctionProduct = await _db.AuctionProduct.Where(ap => ap.AuctionId == a.Id).Include(a => a.Product).ToListAsync();

                if (a.BeginDate > currentDate && status == SD.UpcomingStatus)
                {
                    filterAuctions.Add(item);
                }
                if (a.BeginDate <= currentDate && a.EndDate >= currentDate && status == SD.ActiveStatus)
                {
                    filterAuctions.Add(item);
                }
                if (a.EndDate < currentDate && status == SD.PastStatus)
                {
                    filterAuctions.Add(item);
                }
            }

            auItems.Auctions = filterAuctions;

            return(View(auItems));
        }
        public IActionResult BidItem(AuctionItemViewModel ViewModel)
        {
            if (Logged_user == null)
            {
                return(RedirectToAction(""));
            }

            Auction theAuction = _context.auctions.Where(a => a.id == (int)HttpContext.Session.GetInt32("AuctionId")).SingleOrDefault();

            int CurrentBid = 0;

            List <Bid> allBids = _context.bids.Where(b => b.auctionid == theAuction.id).OrderByDescending(b => b.amount).ToList();
            Bid        highBid = new Bid();

            if (allBids.Count() == 0)
            {
                CurrentBid = 0;
            }
            else
            {
                highBid    = allBids.First();
                CurrentBid = highBid.amount;
            }


            if (ModelState.IsValid)
            {
                if (Logged_user.id == theAuction.creatorid)
                {
                    TempData["Error"] = "You cannot bid on your own auction";
                }
                else
                {
                    DateTime currDate = DateTime.Now;
                    if (currDate < theAuction.ending_at &&
                        theAuction.sold_for == 0)
                    {
                        Bid newBid = new Bid();
                        if (ViewModel.amount <= Logged_user.available_funds)
                        {
                            if (ViewModel.amount > 0 &&
                                ViewModel.amount > CurrentBid &&
                                ViewModel.amount >= theAuction.opening_bid)
                            {
                                newBid.userid     = Logged_user.id;
                                newBid.auctionid  = theAuction.id;
                                newBid.amount     = ViewModel.amount;
                                newBid.created_at = DateTime.Now;

                                _context.bids.Add(newBid);
                                _context.SaveChanges();

                                return(RedirectToAction("GetAuctions"));
                            }
                            else
                            {
                                TempData["Error"] = "Bid is too low, must be greater than opening bid and current high bid";
                            }
                        }
                        else
                        {
                            TempData["Error"] = "Bid exceeds your available funds";
                        }
                    }
                    else
                    {
                        TempData["Error"] = "Bidding for this Auction has ended";
                    }
                }
            }


            User highBidder = new User();

            if (allBids.Count() == 0)
            {
                highBid.id            = 0;
                highBid.userid        = 0;
                highBid.auctionid     = theAuction.id;
                highBid.amount        = 0;
                highBid.created_at    = DateTime.Now;
                highBidder.id         = 0;
                highBidder.first_name = "... Nobody has bid yet";
                highBidder.created_at = DateTime.Now;

                Console.WriteLine("=================== BID is NULL ===============================================");
            }
            else
            {
                highBid    = allBids.First();
                highBidder = _context.users.SingleOrDefault(u => u.id == highBid.userid);
            }

            AuctionItemViewModel reViewModel = new AuctionItemViewModel()
            {
                Current_user        = Logged_user,
                Current_auction     = theAuction,
                Current_bid         = highBid,
                Current_high_bidder = highBidder,
                Current_creator     = _context.users.SingleOrDefault(u => u.id == theAuction.creatorid),
            };

            return(View("AuctionItem", reViewModel));
        }