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)); }
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)); }
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)); }