Ejemplo n.º 1
0
        public ActionResult ViewAuctionDetails(AuctionViewModel model)
        {
            var bidRepo  = new BidRepository();
            var aucRepo  = new AuctionRepository();
            var userRepo = new UserRepository();
            var auction  = aucRepo.GetAuctionById(model.Id);

            model.Bid = aucRepo.GetHighestBid(model.Id);
            var returnModel = auction.ConvertToViewModel();

            if (model.NextBid.Price > (auction.MinPrice + auction.Interval) && model.NextBid.Price > model.Bid.Price)
            {
                model.NextBid.Auction = auction;
                model.NextBid.Active  = true;
                model.NextBid.Date    = DateTime.Now;
                model.NextBid.User    = userRepo.GetUserById(1);
                bidRepo.InsertBid(model.NextBid);

                auction.Bids.Add(model.NextBid);
                returnModel.Bid          = model.NextBid;
                returnModel.ErrorMessage = "Bud på auktionen er godkendt!";
            }
            else
            {
                returnModel.Bid          = model.Bid;
                returnModel.ErrorMessage = "Bud for lavt!";
            }

            return(View(returnModel));
        }
Ejemplo n.º 2
0
        public void Test_Auction_Cannot_Be_Created_Invalid_StartDate()
        {
            var repo = new AuctionRepository();
            var sut  = new AuctionService(repo, null);

            Assert.Throws <ArgumentException>(() => sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(-2)));
        }
Ejemplo n.º 3
0
        public static void RegisterAuctions()
        {
            IEnumerable <Auction> closedAuctions = new List <Auction>();

            using (AppIdentityDbContext context = AppIdentityDbContext.Create())
            //using (IUnitOfWork unitOfWork = new UnitOfWork(context))
            {
                IUnitOfWork        unitOfWork        = new UnitOfWork(context);
                IAuctionRepository auctionRepository = new AuctionRepository(unitOfWork);
                IListingRepository listingRepository = new ListingRepository(unitOfWork);
                IUserRepository    userRepository    = new UserRepository(unitOfWork);
                IAuctionService    auctionService    = new AuctionService(auctionRepository, userRepository, listingRepository, unitOfWork);

                //List<Auction> openAuctions = auctionService.GetAuctions().Where(a => a.IsOpen()).ToList();
                // get auctions that: are not open (have ended), have some bids (which are assumed to be valid), and has no winners assigned yet
                closedAuctions = auctionService.GetAuctionsAsQueryable().Where(a => a.EndTime < DateTime.Now && a.AuctionBids.Count > 0 && a.Winners.Count > 0);

                foreach (Auction auction in closedAuctions)
                {
                    BackgroundJob.Enqueue(() => RegisterAuction(auction.AuctionID));
                }

                auctionService.Dispose();
                auctionRepository.Dispose();
                listingRepository.Dispose();
                userRepository.Dispose();
                unitOfWork.Dispose();
            }
        }
Ejemplo n.º 4
0
        public void Test_Auction_Can_Accept_Bid()
        {
            var user = new User()
            {
                UserName = testUserName
            };
            var userRepo = new UsersRepository();

            userRepo.Add(user);
            userRepo.SetLogin(user, true);

            var repo = new AuctionRepository();
            var sut  = new AuctionService(repo, userRepo);

            var auctionId = sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(1));

            var auction = repo.FindAuctionById(auctionId);
            var myBid   = new Bid {
                amount = 1.75, bidder = "Joe", User = user
            };

            sut.CreateBid(auctionId, 10.0, )
            Assert.True(myBid.amount > auction.HighestBid.amount);
            // public double amount { get; set; }
            // public string bidder { get; set; }
            // public User User { get; set; }
        }
        public void GetById()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }
                using (var db = new AuctionContext(options))
                {
                    var repository = new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));

                    Assert.DoesNotThrow(() => item = repository.GetById(item.Id));
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    Assert.NotNull(item);
                    Assert.Greater(item.Id, 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void MakeBid()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();

                    Assert.DoesNotThrow(() => repository.Save(item));
                    var user = new User
                    {
                        Id = 1
                    };
                    Assert.DoesNotThrow(() => repository.MakeBid(user, item, 1000));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Ejemplo n.º 7
0
 public DataBaseLoadController(AuctionContext auctionContext)
 {
     _auctionContext    = auctionContext;
     _realmRepository   = new RealmRepository(_auctionContext);
     _auctionRepository = new AuctionRepository(_auctionContext);
     _itemRepository    = new ItemRepository(auctionContext);
 }
Ejemplo n.º 8
0
        public void BeforeScenario()
        {
            _context.Auctions = new List <Auction>();
            IAuctionRepository repo = new AuctionRepository(_context.Auctions);

            _context.Controller = new AuctionController(repo);
        }
        public void RemoveLayout()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);
                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    var layout = new AuctionLayout
                    {
                        Title       = "title",
                        Description = "description",
                        Layout      = GenerateAttachment(),
                        AuctionId   = item.Id
                    };
                    Assert.DoesNotThrow(() => repository.AddLayout(item, layout));
                    Assert.DoesNotThrow(() => repository.RemoveLayout(item, layout));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void GetAuctionCategories()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.AddCategory(item, new Category
                    {
                        Id = 1
                    }));
                    IEnumerable <Category> result = null;
                    Assert.DoesNotThrow(() => result = repository.GetAuctionCategories(item.Id));
                    Assert.True(result != null && result.Any());
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void Activate()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }


                using (var db = new AuctionContext(options))
                {
                    var repository = new AuctionRepository(db);
                    var item       = GenerateModel();
                    item.IsActive = false;
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.Activate(item));
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    Assert.IsTrue(item.IsActive);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void RemoveCategory()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.AddCategory(item, new Category
                    {
                        Id = 1
                    }));
                    Assert.DoesNotThrow(() => repository.RemoveCategory(item, new Category
                    {
                        Id = 1
                    }));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Ejemplo n.º 13
0
        public ActionResult GetAll()
        {
            AuctionRepository repository = new AuctionRepository();

            ModelState.Clear();
            return(View(repository.GetAll()));
        }
Ejemplo n.º 14
0
        public dynamic GetAuctionListDataBYAuctionDate(DateTime date)
        {
            dynamic           auctionList = 0;
            AuctionRepository repo        = new AuctionRepository();

            auctionList = repo.GetAuctionListDataBYAuctionDate(date);
            return(auctionList);
        }
Ejemplo n.º 15
0
        public dynamic RecordCount()
        {
            dynamic           count = 0;
            AuctionRepository repo  = new AuctionRepository();

            count = repo.RecordCount();
            return(count);
        }
Ejemplo n.º 16
0
        public dynamic AuctionRemainingVehicleLists(DateTime AuctionDate)
        {
            dynamic           auctionList = 0;
            AuctionRepository repo        = new AuctionRepository();

            auctionList = repo.AuctionRemainingVehicleLists(AuctionDate);
            return(auctionList);
        }
Ejemplo n.º 17
0
        public bool SaveDataAuctionList(List <AuctionListModel> auction)
        {
            bool status            = true;
            AuctionRepository repo = new AuctionRepository();

            status = repo.SaveRepoAuctionList(ParserAddAuctionList(auction));
            return(status);
        }
Ejemplo n.º 18
0
        // GET: Auction/Edit/5
        public ActionResult Edit(int id)
        {
            AuctionRepository repository = new AuctionRepository();

            AuctionModel model = repository.GetById(id);

            return(View(model));
        }
Ejemplo n.º 19
0
 public void AuctionTestInitialize()
 {
     Console.Out.Write("AuctionTestInitialize called...");
     _auctionRepository = new AuctionRepository();
     _artworkRepository = new ArtworkRepository();
     _bidRepository     = new BidRepository();
     _auction           = new Auction();
 }
Ejemplo n.º 20
0
 public void BidTestInitialize()
 {
     Console.Out.Write("BidTestInitialize called...");
     _bidRepository     = new BidRepository();
     _auctionRepository = new AuctionRepository();
     _userRepository    = new UserRepository();
     _bid = new Bid();
 }
Ejemplo n.º 21
0
        public dynamic AuctionFrontEndID()
        {
            AuctionRepository repo    = new AuctionRepository();
            dynamic           vehicle = repo.AuctionFrontEnd();

            //listVehicles = ParserVehiclesForPDF(vehicle);
            return(vehicle);
        }
Ejemplo n.º 22
0
        public void Test_Auction_Cannot_Be_Created_User_Not_Authenticated()
        {
            var repo     = new AuctionRepository();
            var userRepo = new UsersRepository();
            var sut      = new AuctionService(repo, userRepo);

            Assert.Throws <Exception>(() => sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(2)));
        }
Ejemplo n.º 23
0
 public AuctionService()
 {
     _unitOfWork         = new UnitOfWork(new AnonymousBidderDataContext());
     _filePathRepository = new FilePathRepository(_unitOfWork);
     _auctionRepository  = new AuctionRepository(_unitOfWork);
     _abUserRepository   = new ABUserRepository(_unitOfWork);
     _userRoleRepository = new UserRoleRepository(_unitOfWork);
     _bidRepository      = new BidRepository(_unitOfWork);
 }
Ejemplo n.º 24
0
        public dynamic GetAuctionListVehicles()
        {
            //List<Vehicles> listVehicles = new List<Vehicles>();
            AuctionRepository repo    = new AuctionRepository();
            dynamic           vehicle = repo.GetRepoAuctionListVehicles();

            // listVehicles = ParserGetAllVehicles(vehicle);
            return(vehicle);
        }
Ejemplo n.º 25
0
        public dynamic GetVehiclesForPDF(int id)
        {
            //List<Vehicles> listVehicles = new List<Vehicles>();
            AuctionRepository repo    = new AuctionRepository();
            dynamic           vehicle = repo.GetVehicleForAuctionListPDF(id);

            //listVehicles = ParserVehiclesForPDF(vehicle);
            return(vehicle);
        }
Ejemplo n.º 26
0
 public UnitOfWork(AuctionDbContext context, IHostingEnvironment hostingEnvironment)
 {
     _context            = context;
     _hostingEnvironment = hostingEnvironment;
     Artworks            = new ArtworksRepository(context);
     Auctions            = new AuctionRepository(context, hostingEnvironment);
     Authors             = new AuthorsRepository(context);
     Categories          = new CategoryRepository(context);
     Users  = new UserRepository(context, hostingEnvironment);
     Offers = new OffersRepository(context);
 }
Ejemplo n.º 27
0
        public ActionResult ViewAuctionDetails(int id)
        {
            var repo  = new AuctionRepository();
            var model = repo.GetAuctionById(id).ConvertToViewModel();

            model.Bid = repo.GetHighestBid(id) ?? new Bid()
            {
                Price = model.MinPrice
            };
            return(View(model));
        }
Ejemplo n.º 28
0
 public ActionResult CreateAuction(AuctionViewModel model)
 {
     if (ModelState.IsValid)
     {
         var     repo    = new AuctionRepository();
         Auction auction = model.ConvertToBusinessModel();
         auction.Active = true;
         repo.InsertAuction(auction);
     }
     model.Artworks = new ArtworkRepository().GetAllArtworks().ToList();
     return(View(model));
 }
Ejemplo n.º 29
0
        public ActionResult Edit(int id, AuctionModel ModelObject)
        {
            try
            {
                AuctionRepository repository = new AuctionRepository();
                repository.Update(ModelObject);

                return(RedirectToAction("GetAll"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 30
0
        // GET: Auction/Delete/5
        public ActionResult Delete(int id)
        {
            try
            {
                AuctionRepository repository = new AuctionRepository();
                repository.Delete(id);

                return(RedirectToAction("GetAll"));
            }
            catch
            {
                return(View());
            }
        }