Ejemplo n.º 1
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"));
        }
Ejemplo n.º 2
0
        public ActionResult FinishManually(int id)
        {
            try
            {
                Auction auction        = AuctionService.GetByID(id);
                bool    finishManually = true;
                AuctionService.Finish(auction, finishManually);
                HangfireService.CancelJob(auction.CompletionJobID);

                return(Json(new { result = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { result = "Error: " + ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public ActionResult MoveToArchives(int id)
        {
            User user = _userService.GetUserByEmail(User.Identity.Name);
            Auto auto = user.Autoes.FirstOrDefault(a => a.ID == id);

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

            try
            {
                bool moveManually = true;
                _autoService.MoveToArchives(auto, moveManually);
                HangfireService.CancelJob(auto.CompletionJobID);
            }
            catch
            {
                return(HttpNotFound());
            }

            Thread.Sleep(1000);
            return(RedirectToAction("Index", new { statusID = 3 }));
        }
Ejemplo n.º 4
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));
        }