Example #1
0
        /// <summary>
        /// Does the check.
        /// </summary>
        /// <param name="personOfferor">The person offer.</param>
        /// <param name="auction">The auction.</param>
        /// <param name="offerorAuctions">The offer person auctions.</param>
        /// <param name="allProducts">All products.</param>
        /// <returns>
        /// true if the auction can be posted.
        /// </returns>
        public static bool DoCheck(PersonOfferor personOfferor, Auction auction, List <Auction> offerorAuctions, List <Product> allProducts)
        {
            PersonOfferorService offerorService = new PersonOfferorService(personOfferor);

            //// if it's banned.
            if (offerorService.IsBanned)
            {
                return(false);
            }

            //// can't have more than this.
            bool hasMaxAuctions = offerorService.DidPersonHitMaxListLimit(personOfferor, offerorAuctions);

            if (hasMaxAuctions)
            {
                return(false);
            }

            //// can't have more than this in specified category.
            List <Auction> offerorCategoryAuctions = new List <Auction>();

            foreach (Auction listed_auction in offerorAuctions)
            {
                if (listed_auction.Product.Category.Name.Equals(auction.Product.Category.Name))
                {
                    offerorCategoryAuctions.Add(listed_auction);
                }
            }

            bool hasMaxInCategory = offerorService.DidPersonHitMaxCategoryListLimit(personOfferor, auction.Product.Category, offerorCategoryAuctions);

            if (hasMaxInCategory)
            {
                return(false);
            }

            AuctionService auctionService = new AuctionService(auction);

            //// if it's older
            if (DateTime.Now.CompareTo(auction.StartDate) > 0)
            {
                //// it should not be older than 5 min.
                bool olderThanMinutes = (DateTime.Now - auction.StartDate).TotalMinutes > 5;
                if (olderThanMinutes)
                {
                    ////return false;
                }
            }

            bool anySimilarExists = ExistsAnySimilarProductCheck.DoCheck(auction.Product, allProducts);

            //// should not be similar.
            if (anySimilarExists)
            {
                Log.Info(auction.Product.Name + " already exists due to LevensteinDistance!");
                return(false);
            }

            return(true);
        }
Example #2
0
        public static void Main()
        {
            Console.WriteLine("DotNetBay Commandline");

            AuctionRunner auctionRunner = null;

            try
            {
                var store          = new FileSystemMainRepository("store.json");
                var auctionService = new AuctionService(store, new SimpleMemberService(store));

                auctionRunner = new AuctionRunner(store);

                Console.WriteLine("Started AuctionRunner");
                auctionRunner.Start();

                var allAuctions = auctionService.GetAll();

                Console.WriteLine("Found {0} auctions returned by the service.", allAuctions.Count());

                Console.Write("Press enter to quit");
                Console.ReadLine();
            }
            finally
            {
                if (auctionRunner != null)
                {
                    auctionRunner.Dispose();
                }
            }

            Environment.Exit(0);
        }
Example #3
0
        public ActionResult Index(string code)
        {
            var auctions = this.Session["Auctions"] as List <Auction>;

            if (auctions == null)
            {
                auctions = AuctionService.GetAllAuctions();
                this.Session["Auctions"] = auctions;
            }
            var auction = auctions.FirstOrDefault(a => a.Code == code);

            var items = this.Session[code] as List <Item>;

            if (items == null)
            {
                items = AuctionService.GetAuctionItems(code);
                this.Session[code] = items;
            }

            if (this.Session["RegistredInAuctions"] == null)
            {
                this.Session["RegistredInAuctions"] = new List <string>();
            }
            bool registered = ((List <string>) this.Session["RegistredInAuctions"]).Contains(auction.Code);
            var  model      = new AuctionDetailViewModel
            {
                Auction    = auction,
                Items      = items,
                Registred  = registered,
                ActiveItem = registered ? AuctionService.GetCurrentlyAuctionedItem(auction.Code) : null
            };

            return(this.View(model));
        }
Example #4
0
        public ActionResult Delete(int ID)
        {
            AuctionService service = new AuctionService();
            var            auction = service.GetAuctionByID(ID);

            return(PartialView(auction));
        }
Example #5
0
        public ActionResult Delete(Auction auction)
        {
            AuctionService service = new AuctionService();

            service.DeleteAuction(auction);
            return(RedirectToAction("Index"));
        }
Example #6
0
        public ActionResult Edit(Auction auction)
        {
            AuctionService service = new AuctionService();

            service.UpdateAuction(auction);
            return(RedirectToAction("Index"));
        }
Example #7
0
        public void GivenTwoCreatedAuctionsByASingleUser_GetAuctionsByUsername_ReturnsListContainingBothAuctions()
        {
            // Arrange
            const string username = "******";
            var          userFake = new UserRepositoryFake();

            userFake.CreateUser(username, "123456");
            var auctionService = new AuctionService(new AuctionRepositoryFake(), userFake, new AuditRepositoryFake());

            auctionService.CreateAuction(username, new AuctionItemViewModel {
                Description = "description", MinAmount = "0", Name = "Item 1"
            });
            auctionService.CreateAuction(username, new AuctionItemViewModel {
                Description = "description 2", MinAmount = "0", Name = "Item 2"
            });

            // Act
            var allAuctionsByUsername = auctionService.GetAuctionsByUsername(username);

            // Assert
            var auctionViewModels = allAuctionsByUsername.ToList();
            var firstAuction      = auctionViewModels.FirstOrDefault();
            var lastAuction       = auctionViewModels.LastOrDefault();

            Assert.AreEqual(2, auctionViewModels.Count);
            Assert.AreEqual(username, firstAuction.Seller);
            Assert.AreEqual(username, lastAuction.Seller);
        }
Example #8
0
        // View auction
        public List <IAuction> ViewAuction()
        {
            AuctionService viewClient = new AuctionService();
            var            data       = viewClient.LoadAuctions();

            List <IAuction> auctions = new List <IAuction>();

            foreach (var row in data)
            {
                auctions.Add(new Auction
                {
                    Id            = row.Id,
                    Status        = row.Status,
                    CurrentPrice  = row.CurrentPrice,
                    MaxPrice      = row.MaxPrice,
                    Bid           = row.Bid,
                    EndDate       = row.EndDate,
                    Title         = row.Title,
                    Description   = row.Description,
                    Category      = row.Category,
                    CurrentWinner = row.CurrentWinner
                });
            }
            return(auctions);
        }
Example #9
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; }
        }
Example #10
0
        public ActionResult Publish(int id) //auction ID
        {
            User    user    = UserService.GetUserByEmail(User.Identity.Name);
            Auction auction = AuctionService.GetByID(id);

            if (auction == null || auction.Auto.UserID != user.ID)
            {
                return(HttpNotFound());
            }

            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auction.Auto.PriceUSD, auction.Auto.PriceUAH);

            AuctionCreateVM auctionCreateVM = auction;

            AutoDetailsVM      autoVM        = auction.Auto;
            List <AutoPhotoVM> orderedPhotos = autoVM.AutoPhotoes.OrderByDescending(p => p.IsMain).ToList();
            AutoPhotoVM        mainPhoto     = orderedPhotos[0];

            ViewBag.mainPhoto = mainPhoto;

            ViewBag.autoVM = autoVM;

            breadcrumbs.Add("#", Resource.AuctionCreate);
            ViewBag.breadcrumbs = breadcrumbs;

            int limit = 2000;

            int.TryParse(XCarsConfiguration.AutoDescriptionMaxLength, out limit);
            ViewBag.autoDescriptionMaxLength = limit;

            return(View("Create", auctionCreateVM));
        }
Example #11
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)));
        }
Example #12
0
        public void UploadExistDates(int regulationId, DateTime auctionDate)
        {
            var regulation = AuctionService.ReadRegulation(regulationId);

            if (regulation == null)
            {
                return;
            }

            IsAuto = false;

            AutoDate();

            Order.Date     = regulation.openDate;
            Order.Deadline = regulation.applyDeadLine;

            SetOrderDeadLine(16, 0);

            Order.Auction.Date = auctionDate;
            Order.Auction.ApplicantsDeadline = regulation.applicantsDeadLine;
            ProcessingDate = regulation.openDate;
            Order.Auction.ExchangeProvisionDeadline = regulation.provisionDeadLine;

            IsAuto = true;

            AutoDate();
        }
Example #13
0
        public void GivenAuctionsByASingleUser_GetAuctionsByUsername_WithDifferentUsername_ReturnsEmptyList()
        {
            // Arrange
            const string pera     = "Pera";
            const string mika     = "Mika";
            var          userFake = new UserRepositoryFake();

            userFake.CreateUser(pera, "123456");
            userFake.CreateUser(mika, "654321");

            var auctionService = new AuctionService(new AuctionRepositoryFake(), userFake, new AuditRepositoryFake());

            auctionService.CreateAuction(pera, new AuctionItemViewModel {
                Description = "description", MinAmount = "0", Name = "Item 1"
            });
            auctionService.CreateAuction(pera, new AuctionItemViewModel {
                Description = "description 2", MinAmount = "0", Name = "Item 2"
            });

            // Act
            var allAuctionsByUsername = auctionService.GetAuctionsByUsername(mika);

            // Assert
            Assert.IsEmpty(allAuctionsByUsername);
        }
Example #14
0
 public MainWindow()
 {
     InitializeComponent();
     var app = Application.Current as App;
     var auctionService = new AuctionService(app.MainRepository, new SimpleMemberService(app.MainRepository));
     DataContext = new MainViewModel(app.AuctionRunner.Auctioneer, auctionService);
 }
Example #15
0
        public async Task CanCancelBidByOrder()
        {
            Product cancelProductBid = new Product();

            cancelProductBid.Name = "CanCancelBidByOrder";
            cancelProductBid.AvailableEndDateTimeUtc = DateTime.Now.AddDays(5);
            cancelProductBid.ProductType             = ProductType.Auction;
            cancelProductBid.HighestBid    = 10;
            cancelProductBid.HighestBidder = "H";
            _productRepository.Insert(cancelProductBid);

            var productService = new Mock <IProductService>();

            productService.Setup(x => x.GetProductById(cancelProductBid.Id, false)).ReturnsAsync(cancelProductBid);
            var _cancelproductService = productService.Object;
            var _cancelauctionService = new AuctionService(_bidRepository, _cancelproductService, _productRepository, _cacheManager, _eventPublisher);

            Bid bid = new Bid();

            bid.Amount    = 1;
            bid.OrderId   = "o";
            bid.ProductId = cancelProductBid.Id;
            _bidRepository.Insert(bid);
            await _cancelauctionService.CancelBidByOrder("o");

            var found = await _cancelauctionService.GetBidsByProductId("CanCancelBidByOrder");

            var product = _productRepository.Table.Where(x => x.Name == "CanCancelBidByOrder").FirstOrDefault();

            Assert.AreEqual(0, found.Count);
            Assert.AreEqual(0, product.HighestBid);
            Assert.AreEqual("", product.HighestBidder);
            Assert.AreEqual(false, product.AuctionEnded);
        }
Example #16
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();
            }
        }
Example #17
0
        private AuctionService CreateAuctionService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new AuctionService(userId);

            return(service);
        }
Example #18
0
        public App()
        {
            this.MainRepository = new FileSystemMainRepository("appdata.json");
            this.MainRepository.SaveChanges();

            var memberService = new SimpleMemberService(this.MainRepository);
            var service       = new AuctionService(this.MainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();

                service.Save(new Auction
                {
                    Title            = "My First Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Seller           = me
                });
            }

            this.AuctionRunner = new AuctionRunner(this.MainRepository);
            this.AuctionRunner.Start();
        }
Example #19
0
        public ActionResult MoveToArchives(int id)
        {
            User    user    = UserService.GetUserByEmail(User.Identity.Name);
            Auction auction = AuctionService.GetByID(id);

            if (auction == null || auction.Auto.UserID != user.ID)
            {
                return(HttpNotFound());
            }

            try
            {
                bool moveManually = true;
                AuctionService.Finish(auction, moveManually);
                HangfireService.CancelJob(auction.CompletionJobID);
                HangfireService.CancelJob(auction.DeletionJobID);
            }
            catch
            {
                return(HttpNotFound());
            }

            Thread.Sleep(1000);
            return(RedirectToAction("Index", "MyAuto"));
        }
Example #20
0
 public UserController(ApplicationDbContext context, IInventoryService inventoryService, AuctionService auctionService, IStringLocalizer <UserController> localizer)
 {
     _context          = context;
     _inventoryService = inventoryService;
     _auctionService   = auctionService;
     _localizer        = localizer;
 }
        /// <summary>
        /// Logs in the user with a popup dialog for the google auth UI
        /// </summary>
        /// <param name="service">The object to extend</param>
        /// <param name="ctx">The UI context to use for rooting the login dialog.</param>
        public static async Task Login(this AuctionService service, Context ctx)
        {
            var auctionService = App.GetAuctionService();
            var client         = new MobileServiceClient(auctionService.ServiceBaseUri);
            var user           = await client.LoginAsync(ctx, MobileServiceAuthenticationProvider.Google);

            auctionService.CurrentUser = user;
        }
Example #22
0
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new AuctionService(userId);
            var model   = service.GetAuctions();

            return(View(model));
        }
Example #23
0
        public void AuctionService_Sale_ReturnsAuctionData()
        {
            var target = new AuctionService();

            var data = target.GetAuctions(new AuctionQueryRequestMessage(AuctionType.Sale)).Result;

            TestContext.WriteLine(JsonConvert.SerializeObject(data));
        }
Example #24
0
        public void GetByID_EntityNotFound()
        {
            this.mockRepository.Setup(x => x.GetByID(It.IsAny <object>()));

            var services = new AuctionService(this.mockRepository.Object);

            services.GetByID(0).Should().BeNull();
        }
Example #25
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)));
        }
        public bool InsertBid(Bid bid)
        {
            AuctionService aS = new AuctionService();

            bool successful = aS.InsertBid(bid);

            return(successful);
        }
 public void ArrangeBeforeEachTest()
 {
     secondChildViewModel = new SecondChildViewModel();
     firstChildViewModel  = new FirstChildViewModel();
     auctionService       = new AuctionService();
     auctionRepos         = new AuctionRepos();
     userService          = new UserService();
 }
Example #28
0
        // GET: Auctions
        public ActionResult Index()
        {
            var auctions = AuctionService.GetAllAuctions();

            this.Session["Auctions"]  = auctions;
            this.ViewData["Auctions"] = auctions;
            return(View());
        }
Example #29
0
        public void RunTest()
        {
            PrintTestTitle();
            CollectionWithSQL result = AuctionService.FindAllAuctions();

            PrintAuctions(result.TheCollection);
            PrintSQL(result.TheSql);
            CloseResult();
        }
Example #30
0
        public BidView(Auction auction)
        {
            InitializeComponent();
            var app            = Application.Current as App;
            var memberService  = new SimpleMemberService(app.MainRepository);
            var auctionService = new AuctionService(app.MainRepository, memberService);

            this.DataContext = new BidViewModel(auction, memberService, auctionService);
        }
Example #31
0
 protected void WhenAnAuctionServiceIsConstructed()
 {
     var service = new AuctionService();
 }
Example #32
0
 protected void WhenAnAuctionIsCreatedWithSettings(BiddingMethod BiddingMethod, DateTime EndDate)
 {
     var service = new AuctionService();
     this.ReturnedAuctionIdentity = service.CreateAuction(BiddingMethod, EndDate);
 }