public async Task <IActionResult> Index(Model model) { if (User.Identity.IsAuthenticated && User.IsInRole("admin")) { if (!ModelState.IsValid) { return(NotFound()); } if (_context.Models.Any(m => m.Name == model.Name)) { ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ModelState.AddModelError("Model.Name", "Model is already exsist"); LoadModelsAdminVM vM = new LoadModelsAdminVM { Models = _context.Models.Include(m => m.Brand).OrderBy(c => c.Name) }; return(View(vM)); } Model newM = new Model { Name = model.Name, BrandId = model.BrandId }; await _context.Models.AddAsync(newM); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Index(Brand brand) { if (User.Identity.IsAuthenticated && User.IsInRole("admin")) { if (!ModelState.IsValid) { return(NotFound()); } if (_context.Brands.Any(b => b.Name == brand.Name)) { ModelState.AddModelError("Brand.Name", "Brand is already exsist"); LoadBrandsAdminVM vM = new LoadBrandsAdminVM { Brands = _context.Brands.OrderBy(c => c.Name) }; return(View(vM)); } Brand newB = new Brand { Name = brand.Name }; await _context.Brands.AddAsync(newB); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Chat(Message message, int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (id == null || !_context.Orders.Any(o => o.Id == id) || message == null) { return(PartialView("ErrorPage")); } Message newMessage = new Message { From = "moderator", To = _context.Orders.Where(o => o.Id == id).Include(o => o.Advertisement).Include(o => o.Advertisement.ApplicationUser).FirstOrDefault().Advertisement.ApplicationUserId, Body = message.Body, Date = DateTime.Now, }; await _context.Messages.AddAsync(newMessage); ChatMessage newChatMessage = new ChatMessage { ChatId = _context.Chats.Where(c => c.OrderId == id).FirstOrDefault().Id, MessageId = newMessage.Id }; await _context.ChatMessages.AddAsync(newChatMessage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Chat))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Details(int?id, Message message) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (id == null || !_context.Advertisements.Any(ad => ad.Id == id)) { return(NotFound()); } if (!ModelState.IsValid) { return(NotFound()); } Message newMessage = new Message { Body = message.Body, Title = "Your advertisement is not accepted", From = _context.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault().Id, To = _context.Advertisements.Where(ad => ad.Id == id).FirstOrDefault().ApplicationUserId, Date = DateTime.Now }; await _context.Messages.AddAsync(newMessage); AdvertisementMessage advertisementMessage = new AdvertisementMessage { MessageId = newMessage.Id, AdvertisementId = (int)id }; await _context.AdvertisementMessages.AddAsync(advertisementMessage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Index(Country country) { if (User.Identity.IsAuthenticated && User.IsInRole("admin")) { if (!ModelState.IsValid) { return(PartialView("ErrorPage")); } if (_context.Countries.Any(c => c.Name == country.Name)) { LoadCountriesAdminVM vM = new LoadCountriesAdminVM { Countries = _context.Countries.OrderBy(c => c.Name) }; ModelState.AddModelError("Country.Name", "Country is already exsist"); return(View(vM)); } Country newC = new Country { Name = country.Name }; await _context.Countries.AddAsync(newC); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Edit(SectionBanner banner) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (banner == null) { return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { return(PartialView("ErrorPage")); } SectionBanner bannerDb = _context.SectionBanners.Find(banner.Id); if (!banner.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Photo should be image"); return(View(bannerDb)); } RemovePhoto(_env.WebRootPath, bannerDb.ImageUrl); bannerDb.ImageUrl = await banner.Photo.SavePhotoAsync(_env.WebRootPath, "SectionBanners"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Index(Contact contact) { if (contact == null) { ViewBag.IsHeaderNonVisible = true; return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { ViewBag.IsHeaderNonVisible = true; return(NotFound()); } Contact newContact = new Contact { Name = contact.Name, Email = contact.Email, Message = contact.Message, Date = DateTime.Now }; await _context.Contacts.AddAsync(newContact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> ConfirmEmail(string id) { if (id == null) { return(NotFound()); } ApplicationUser confirmedUser = await _userManager.FindByIdAsync(id); if (confirmedUser == null) { return(NotFound()); } confirmedUser.EmailConfirmed = true; await _context.SaveChangesAsync(); return(View(confirmedUser)); }
public async Task <IActionResult> EditVision(OurVisionAboutUs vision) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (vision == null || !_context.OurVisions.Any(v => v.Id == vision.Id) || !ModelState.IsValid) { return(PartialView("ErrorPage")); } OurVisionAboutUs visionDb = _context.OurVisions.Where(v => v.Id == vision.Id).FirstOrDefault(); visionDb.Header = vision.Header; visionDb.Content = vision.Content; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> DeleteReview(int id) { Review review = await _context.Reviews.FindAsync(id); int adId = review.AdvertisementId; _context.Reviews.Remove(review); await _context.SaveChangesAsync(); return(PartialView("_LoadReviewsPartial", _context.Reviews.Where(r => r.AdvertisementId == adId).OrderByDescending(r => r.Date))); }
public async Task <IActionResult> Reject(int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("member")) { if (id == null || !_context.Orders.Any(o => o.Id == id)) { return(PartialView("ErrorPage")); } Order order = await _context.Orders.FindAsync(id); SmtpClient client = new SmtpClient("smtp.office365.com", 587) { UseDefaultCredentials = false, EnableSsl = true, Credentials = new NetworkCredential("*****@*****.**", "elmar1999@") }; MailMessage message = new MailMessage("*****@*****.**", order.Email) { IsBodyHtml = true, Subject = "Your order is rejected", Body = $"<a href='http://www.therentnow.com/Cars/Details/{order.AdvertisementId}'>Dear {order.Firstname} {order.Lastname},your order is rejected.Click for car details </a>" + "<div style='width:100%'>" + "<div style='width:23%;display:inline-block;background-color:#1876D2;height:3px'></div>" + "<h3 style='font-size: 1.80203rem;line-height: 36px;margin:0;margin-bottom:20px'>Elmar Ibrahimli</h3>" + "<p style='color:#00D231; display:inline;font-size: 30px;font-style: italic;font-weight: bold;'>RENT</p><p style='color:black; display:inline;font-size: 30px;font-style: italic;font-weight: bold;'>NOW</p>" + "<a href='tel:+994703347347' style='color: rgb(9,117,122);display:block'> +994703347347</a>" + "<a href='www.therentnow.com' target='_blank' style='color: rgb(9,117,122);display:block'>therentnow.com</a>" + "</div>" }; await client.SendMailAsync(message); _context.Orders.Remove(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Book(Order order, int?id) { if (order == null) { return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { return(NotFound()); } BookVM vM = new BookVM { Advertisement = _context.Advertisements.Where(ad => ad.Id == id).Include(ad => ad.Car).Include(ad => ad.Car.Model).Include(ad => ad.Car.Model.Brand).FirstOrDefault(), Order = order }; if (order.PickDate < DateTime.Now.AddDays(2)) { ModelState.AddModelError("Order.PickDate", "Pick up date must be larger than 3 days from now"); ViewBag.Banner = _context.SectionBanners.Where(b => b.SectionName == "Booking").FirstOrDefault().ImageUrl; ViewBag.Price = _context.Cars.Where(c => c.Advertisement.Id == id).FirstOrDefault().Price; return(View(vM)); } if (order.ReturnDate <= order.PickDate) { ModelState.AddModelError("Order.ReturnDate", "Return date is not valid"); ViewBag.Price = _context.Cars.Where(c => c.Advertisement.Id == id).FirstOrDefault().Price; ViewBag.Banner = _context.SectionBanners.Where(b => b.SectionName == "Booking").FirstOrDefault().ImageUrl; return(View(vM)); } Order newOrder = new Order { AdvertisementId = (int)id, PickDate = order.PickDate, ReturnDate = order.ReturnDate, Firstname = order.Firstname, Lastname = order.Lastname, Email = order.Email, OrderDate = DateTime.Now, ResponseDate = DateTime.Now.AddDays(3), IsResponded = false }; await _context.Orders.AddAsync(newOrder); await _context.SaveChangesAsync(); return(PartialView("OrderCheckedPartial")); }
public async Task <IActionResult> Index(ContactModeratorVM contact, int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (id == null || !_context.Contacts.Any(c => c.Id == id)) { return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { return(NotFound()); } Contact contactFromDb = await _context.Contacts.FindAsync(id); SmtpClient client = new SmtpClient("smtp.office365.com", 587) { UseDefaultCredentials = false, EnableSsl = true, Credentials = new NetworkCredential("*****@*****.**", "elmar1999@") }; MailMessage message = new MailMessage("*****@*****.**", contactFromDb.Email) { IsBodyHtml = true, Subject = "Your message ansewered", Body = contact.Message + "<div style='width:100%'>" + "<div style='width:23%;display:inline-block;background-color:#1876D2;height:3px'></div>" + "<h3 style='font-size: 1.80203rem;line-height: 36px;margin:0;margin-bottom:20px'>Elmar Ibrahimli</h3>" + "<p style='color:#00D231; display:inline;font-size: 30px;font-style: italic;font-weight: bold;'>RENT</p><p style='color:black; display:inline;font-size: 30px;font-style: italic;font-weight: bold;'>NOW</p>" + "<a href='tel:+994703347347' style='color: rgb(9,117,122);display:block'> +994703347347</a>" + "<a href='www.therentnow.com' target='_blank' style='color: rgb(9,117,122);display:block'>therentnow.com</a>" + "</div>" }; await client.SendMailAsync(message); _context.Contacts.Remove(contactFromDb); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> DeleteContent(int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (id == null) { return(PartialView("ErrorPage")); } if (!_context.TermContents.Any(t => t.Id == id)) { return(PartialView("ErrorPage")); } TermContent term = await _context.TermContents.Where(t => t.Id == id).FirstOrDefaultAsync(); _context.Remove(term); await _context.SaveChangesAsync(); return(Redirect("/moderator/TermsModerator")); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Create(Blog blog) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (blog == null) { return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { return(NotFound()); } if (blog.Content.Length < 300) { ModelState.AddModelError("Content", "Content is too short"); return(View(blog)); } Blog newBlog = new Blog(); await _context.AddAsync(newBlog); if (blog.MainPhoto == null) { ModelState.AddModelError("MainPhoto", "Main image should be selected"); return(View(blog)); } if (!blog.MainPhoto.ContentType.Contains("image/")) { ModelState.AddModelError("MainPhoto", "File type should be image"); return(View(blog)); } newBlog.MainImageUrl = await blog.MainPhoto.SavePhotoAsync(_env.WebRootPath, "blogs"); newBlog.Header = blog.Header; newBlog.Content = blog.Content; newBlog.PublishDate = DateTime.Now; newBlog.UpdatedDate = DateTime.Now; if (blog.DetailPhotos != null) { foreach (var photo in blog.DetailPhotos) { if (!photo.ContentType.Contains("image/")) { ModelState.AddModelError("DetailPhotos", "File type should be image"); return(View(blog)); } } foreach (var photo in blog.DetailPhotos) { BlogDetailImage detailImage = new BlogDetailImage { BlogId = newBlog.Id, ImageUrl = await photo.SavePhotoAsync(_env.WebRootPath, "blogs") }; await _context.BlogDetailImages.AddAsync(detailImage); } } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Edit(Advertisement advertisement) { if (User.Identity.IsAuthenticated && User.IsInRole("member")) { if (advertisement == null) { return(PartialView("ErrorPage")); } if (!ModelState.IsValid) { ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; return(NotFound()); } if (!_context.Models.Any(m => m.Id == advertisement.Car.ModelId)) { ModelState.AddModelError("Car.ModelId", "Model is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.Cities.Any(c => c.Id == advertisement.Car.CityId)) { ModelState.AddModelError("Car.CityId", "City is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.BodyTypes.Any(b => b.Id == advertisement.Car.BodyTypeId)) { ModelState.AddModelError("Car.BodyTypeId", "Body type is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.Transmissions.Any(t => t.Id == advertisement.Car.TransmissionId)) { ModelState.AddModelError("Car.TransmissionId", "Transmission is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.FuelTypes.Any(f => f.Id == advertisement.Car.FuelTypeId)) { ModelState.AddModelError("Car.FuelTypeId", "Fuel type is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.Colors.Any(c => c.Id == advertisement.Car.ColorId)) { ModelState.AddModelError("Car.ColorId", "Color is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (!_context.WheelDrives.Any(w => w.Id == advertisement.Car.WheelDriveId)) { ModelState.AddModelError("Car.WheelDriveId", "Wheel drive class is not accessible"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } if (advertisement.Car.ManufactureYear < 1900 || advertisement.Car.ManufactureYear > DateTime.Now.Year) { ModelState.AddModelError("Car.ManufactureYear", $"Manufacture year must be between 1900 and {DateTime.Now.Year}"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } Advertisement adFromDb = await _context.Advertisements.Where(ad => ad.Id == advertisement.Id) .Include(ad => ad.Car) .Include(ad => ad.Car.CarDetailImages) .Include(ad => ad.Car.Transmission) .Include(ad => ad.Car.FuelType) .Include(ad => ad.Car.Color) .Include(ad => ad.Car.Model) .Include(ad => ad.Car.Model.Brand) .Include(ad => ad.Car.City) .Include(ad => ad.Car.City.Country) .Include(ad => ad.Car.BodyType) .Include(ad => ad.Car.CarClass) .Include(ad => ad.Car.WheelDrive).FirstOrDefaultAsync(); if (advertisement.Car.Photo != null) { if (!advertisement.Car.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Car.Photo", "File type should be image"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } RemovePhoto(_env.WebRootPath, _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefault().MainImageUrl); adFromDb.Car.MainImageUrl = await advertisement.Car.Photo.SavePhotoAsync(_env.WebRootPath, "advertisements"); } if (advertisement.Car.DetailPhotos != null) { foreach (var photo in advertisement.Car.DetailPhotos) { if (!photo.ContentType.Contains("image/")) { ModelState.AddModelError("Car.DetailPhotos", "File type should be image"); ViewBag.Brands = _context.Brands.OrderBy(b => b.Name); ViewBag.Countries = _context.Countries.OrderBy(c => c.Name); ViewBag.Categories = _context.CarClasses; ViewBag.BodyTypes = _context.BodyTypes; ViewBag.Transmissons = _context.Transmissions; ViewBag.FuelTypes = _context.FuelTypes; ViewBag.Colors = _context.Colors; ViewBag.WheelDrives = _context.WheelDrives; advertisement.Car.CarDetailImages = _context.CarDetailImages.Where(c => c.Car.Advertisement.Id == advertisement.Id).ToList(); advertisement.Car = await _context.Cars.Where(c => c.Advertisement.Id == advertisement.Id).FirstOrDefaultAsync(); return(View(advertisement)); } //await _context.SaveChangesAsync(); } foreach (var photo in advertisement.Car.DetailPhotos) { CarDetailImage detailImage = new CarDetailImage { CarId = adFromDb.CarId, ImageUrl = await photo.SavePhotoAsync(_env.WebRootPath, "advertisements") }; await _context.CarDetailImages.AddAsync(detailImage); } } if (advertisement.Car.Price <= 100) { adFromDb.Car.CarClassId = 1; } if (advertisement.Car.Price > 100 && advertisement.Car.Price <= 200) { adFromDb.Car.CarClassId = 2; } if (advertisement.Car.Price > 200) { adFromDb.Car.CarClassId = 3; } adFromDb.Car.ModelId = advertisement.Car.ModelId; adFromDb.Car.ColorId = advertisement.Car.ColorId; adFromDb.Car.Description = advertisement.Car.Description; adFromDb.Car.FuelTypeId = advertisement.Car.FuelTypeId; adFromDb.Car.IsVip = advertisement.Car.IsVip; adFromDb.Car.ManufactureYear = advertisement.Car.ManufactureYear; adFromDb.Car.Milage = advertisement.Car.Milage; adFromDb.Car.Engine = advertisement.Car.Engine; adFromDb.Car.Price = advertisement.Car.Price; adFromDb.Car.TransmissionId = advertisement.Car.TransmissionId; adFromDb.Car.CityId = advertisement.Car.CityId; adFromDb.Car.BodyTypeId = advertisement.Car.BodyTypeId; adFromDb.Car.WheelDriveId = advertisement.Car.WheelDriveId; adFromDb.UpdatedDate = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }