예제 #1
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));
        }
예제 #2
0
        public ActionResult Create(int id) //auto ID
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);
            Auto auto = user?.Autoes.FirstOrDefault(a => a.ID == id && a.StatusID == 2);

            if (auto == null)
            {
                return(HttpNotFound());
            }

            Auction auction = new Auction()
            {
                AutoID         = auto.ID,
                DateCreated    = DateTime.Now,
                StartPrice     = 0,
                CurrentPrice   = 0,
                PriceUSDSearch = 0,
                PriceUAHSearch = 0,
                CurrencyID     = 1,
                StatusID       = 1, //draft
                Deadline       = DateTime.Now
            };

            AuctionService.Create(auction);
            //string jobID = HangfireService.CreateJobForAuctionDeletion(auction);
            //auction.DeletionJobID = jobID;
            //AuctionService.Edit(auction);

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

            AuctionCreateVM auctionCreateVM = auction;

            AutoDetailsVM      autoVM        = 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(auctionCreateVM));
        }
예제 #3
0
        public ActionResult Create(AuctionCreateVM modelVM)
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);
            Auto auto = user?.Autoes.FirstOrDefault(a => a.ID == modelVM.AutoID);

            if (auto == null)
            {
                return(HttpNotFound());
            }

            Auction auction = AuctionService.GetUnactive(modelVM.ID);

            if (auction == null || auction.AutoID != auto.ID)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //auction.AutoID = modelVM.AutoID;
                    auction.StartPrice   = modelVM.StartPrice;
                    auction.CurrentPrice = modelVM.StartPrice;
                    auction.CurrencyID   = modelVM.CurrencyID;
                    auction.Description  = modelVM.Description;
                    auction.DateCreated  = DateTime.Now;
                    auction.Deadline     = DateTime.Now.AddHours(modelVM.Hours + modelVM.Days * 24);
                    //auction.Deadline = DateTime.Now.AddMinutes(modelVM.Hours);
                    //auction.Deadline = DateTime.Now.AddMinutes(2);
                    auction.StatusID = 2;

                    List <AuctionBid> bids = auction.AuctionBids.ToList();
                    foreach (var item in bids)
                    {
                        AuctionBidService.Delete(item);
                    }

                    //AuctionService.Edit(auction);
                    HangfireService.CancelJob(auction.DeletionJobID);
                    auction.CompletionJobID = HangfireService.CreateJobForAuction(auction);
                    AuctionService.Edit(auction);

                    return(RedirectToAction("Details", "Auction", new { id = auction.ID }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", Resource.SaveError + ": " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", Resource.InvalidData);
            }

            //ViewBag.autoID = auto.ID;
            //ViewBag.auctionID = auction.ID;
            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auto.PriceUSD, auto.PriceUAH);

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

            int limit = 2000;

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

            return(View(modelVM));
        }