public async Task <IActionResult> Delete(int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("member")) { if (id == null) { return(PartialView("ErrorPage")); } if (!_context.Advertisements.Any(ad => ad.Id == id)) { return(PartialView("ErrorPage")); } if (!_context.Advertisements.Where(ad => ad.Id == id).Any(ad => ad.ApplicationUser.UserName == User.Identity.Name)) { return(PartialView("ErrorPage")); } Advertisement advertisement = await _context.Advertisements.Where(ad => ad.Id == id).FirstOrDefaultAsync(); Car car = await _context.Cars.Where(c => c.Id == advertisement.CarId).Include(c => c.CarDetailImages).FirstOrDefaultAsync(); foreach (var img in car.CarDetailImages) { RemovePhoto(_env.WebRootPath, img.ImageUrl); } RemovePhoto(_env.WebRootPath, car.MainImageUrl); _context.Remove(car); _context.Remove(advertisement); await _context.SaveChangesAsync(); return(Redirect("/user/Advertisement")); } ViewBag.IsHeaderNonVisible = true; return(Redirect("/account/login")); }
public async Task <IActionResult> Delete(int?id) { if (User.Identity.IsAuthenticated && User.IsInRole("moderator")) { if (id == null) { return(PartialView("ErrorPage")); } if (!_context.Blogs.Any(b => b.Id == id)) { return(PartialView("ErrorPage")); } Blog blog = await _context.Blogs.Where(b => b.Id == id).Include(b => b.BlogDetailImages).FirstOrDefaultAsync(); foreach (var img in blog.BlogDetailImages) { RemovePhoto(_env.WebRootPath, img.ImageUrl); } RemovePhoto(_env.WebRootPath, blog.MainImageUrl); _context.Remove(blog); await _context.SaveChangesAsync(); return(Redirect("/moderator/Blog")); } 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")); }