コード例 #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
        // GET: SearchAuto
        public ActionResult Index()
        {
            breadcrumbs.Add("#", Resource.Search);
            ViewBag.breadcrumbs = breadcrumbs;

            ViewBag.regions            = CityService.GetAllAsSelectList();
            ViewBag.autoTransportTypes = AutoTransportTypeService.GetAllAsSelectList();
            ViewBag.currencies         = CurrencyService.GetAllAsSelectList();
            ViewBag.years = YearService.GetAllAsSelectList();

            return(View());
        }
コード例 #3
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));
        }
コード例 #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));
        }
コード例 #5
0
        public ActionResult Details(int id)
        {
            //Auto auto = AutoService.GetPublishedByID(id);
            Auto auto = AutoService.GetByID(id);

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

            auto.Views++;
            AutoService.Edit(auto);

            User currentUser = null;

            if (User.Identity.IsAuthenticated)
            {
                currentUser = UserService.GetUserByEmail(User.Identity.Name);
            }

            //double dollarRate = CurrencyService.GetCurrencyRate();

            AutoDetailsVM autoDetailsVM = auto;

            for (int i = 0; i < autoDetailsVM.AutoExchangesIncome.Count; i++)
            {
                autoDetailsVM.AutoExchangesIncome[i].DeleteButtonIsAvailable = (currentUser != null && (currentUser.ID == auto.UserID || currentUser.ID == autoDetailsVM.AutoExchangesIncome[i].Auto.Owner.UserID));
            }


            List <AutoShortInfoVM> autosAvailableForExchangeOffer = null;

            if (currentUser != null)
            {
                List <Auto> tmp = currentUser.Autoes.Where(a => /*a.StatusID == 2
                                                                 * &&*/a.AutoExchangesOutcome.FirstOrDefault(ex => ex.TargetAutoID == id) == null).ToList();
                autosAvailableForExchangeOffer = new List <AutoShortInfoVM>();
                foreach (var item in tmp)
                {
                    autosAvailableForExchangeOffer.Add(item);
                }

                ViewBag.currencies = CurrencyService.GetAllAsSelectList(1);
                //ViewBag.showAddtoFavoriteButton = true;

                if (currentUser.AutoFavorites.FirstOrDefault(f => f.AutoID == id) != null)
                {
                    ViewBag.isInFavorite = true;
                }

                if (currentUser.ID == autoDetailsVM.Owner.UserID)
                {
                    ViewBag.isAbleToAnswerToOffers = true;
                }
            }

            ViewBag.autosAvailableForExchangeOffer = autosAvailableForExchangeOffer;

            //breadcrumbs.Add("/Auto/Index", Resource.Advertisements);
            breadcrumbs.Add("/Auto/Index", autoDetailsVM.Region);
            breadcrumbs.Add("/Auto", autoDetailsVM.Make);
            breadcrumbs.Add("#", autoDetailsVM.Make + " " + autoDetailsVM.Model + " " + autoDetailsVM.YearOfIssue);
            ViewBag.breadcrumbs = breadcrumbs;

            //create search model for getting related
            ExtendedSearchVM searchVM = new ExtendedSearchVM()
            {
                //MakeAndModels = new List<MakeAndModelVM>() { new MakeAndModelVM() { MakeID = auto.MakeID, ModelID = auto.ModelID, ModelToBeExcluded = false } },
                MakeID = new int[1] {
                    auto.MakeID
                },
                ModelID = new int[1] {
                    auto.ModelID
                },
                MakeAndModels = new List <MakeAndModelVM>()
                {
                    new MakeAndModelVM()
                    {
                        MakeID = auto.MakeID, ModelID = auto.ModelID
                    }
                },
                YearOfIssueFrom = auto.YearOfIssue,
                YearOfIssueTo   = auto.YearOfIssue,
                IDsToBeExcluded = new int[1] {
                    auto.ID
                }
            };

            ViewBag.searchVM = searchVM;

            List <AutoPhotoVM> orderedPhotos = autoDetailsVM.AutoPhotoes.OrderByDescending(p => p.IsMain).ToList();
            AutoPhotoVM        mainPhoto     = orderedPhotos[0];

            ViewBag.orderedPhotos = orderedPhotos;

            //Open Graph (for fb share purposes)
            Dictionary <string, string> openGraph = new Dictionary <string, string>();

            openGraph["url"]         = "http://emcar.quadevs.com/Auto/Details/" + id;
            openGraph["type"]        = "page";
            openGraph["title"]       = autoDetailsVM.Make + " " + autoDetailsVM.Model + (!string.IsNullOrWhiteSpace(autoDetailsVM.Modification) ? autoDetailsVM.Modification : "") + " " + autoDetailsVM.YearOfIssue;
            openGraph["description"] = autoDetailsVM.Description;
            openGraph["image"]       = XCarsConfiguration.BucketEndpoint + XCarsConfiguration.BucketName + "/" + XCarsConfiguration.AutoPhotosUploadUrl + (mainPhoto.ID != 0 ? (mainPhoto.ID + "_575x359") : XCarsConfiguration.AutoNoPhotoName) + XCarsConfiguration.PhotoExtension;
            ViewBag.openGraph        = openGraph;

            return(View(autoDetailsVM));
        }