public async Task <IActionResult> DeletePost(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } Gallery gallery = await _context.Gallery.FindAsync(id); string computerPhoto = Path.Combine(_env.WebRootPath, "images", gallery.PhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } _context.Gallery.Remove(gallery); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> EditPost(History history) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ModelState.AddModelError("", "Xaiş olunur düzgün doldurun."); return(View(history)); } History newHistory = await _context.History.FindAsync(history.Id); if (newHistory == null) { return(View("Error")); } newHistory.Info = history.Info; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(GetHistory))); }
public async Task <IActionResult> DeletePost(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } Slider slider = await _context.Slider.FindAsync(id); if (_context.Slider.Count() <= 2) { ModelState.AddModelError("", "Saytda 2 dənədən az slider ola bilməz."); return(View(slider)); } string computerPhoto = Path.Combine(_env.WebRootPath, "images", slider.PhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } _context.Slider.Remove(slider); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeletePost(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } News news = await _context.News.FindAsync(id); IEnumerable <NewsPhotos> myPhoto = news.Photos.Where(b => b.NewsId == news.Id); foreach (var photo in myPhoto) { string computerPhoto = Path.Combine(_env.WebRootPath, "images", photo.PhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } _context.NewsPhotos.RemoveRange(myPhoto); } _context.News.Remove(news); await _context.SaveChangesAsync(); ViewBag.Active = "Home"; return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> EditPost(StaticData staticData) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ModelState.AddModelError("", "Xaiş olunur düzgün doldurun."); return(View(staticData)); } StaticData currentData = await _context.StaticData.FindAsync(staticData.Id); if (currentData == null) { return(View("Error")); } currentData.Email = staticData.Email; currentData.FacebookLink = staticData.FacebookLink; currentData.InstagramLink = staticData.InstagramLink; currentData.Phone = staticData.Phone; currentData.TwitterLink = staticData.TwitterLink; currentData.YoutubeLink = staticData.YoutubeLink; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details))); }
public async Task <IActionResult> EditPost(FirstTeam team) { if (!User.Identity.IsAuthenticated) { ViewBag.Players = _context.Player; return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { ViewBag.Players = _context.Player; return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ViewBag.Players = _context.Player; ModelState.AddModelError("", "Xaiş olunur düzgün doldurun."); return(View(team)); } FirstTeam newTeam = await _context.FirstTeam.FindAsync(team.Id); if (newTeam == null) { return(View("Error")); } newTeam.PlayerId = team.PlayerId; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeletePost(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } Event events = await _context.Event.FindAsync(id); _context.Event.Remove(events); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Contact(MailBox message) { if (!ModelState.IsValid) { ViewBag.Active = "Contact"; return(View(message)); } MailBox mynews = new MailBox() { Firstname = message.Firstname, Lastname = message.Lastname, Email = message.Email, TextBody = message.TextBody, Time = DateTime.Now }; await _context.MailBox.AddAsync(mynews); await _context.SaveChangesAsync(); TempData["MessageSent"] = true; return(RedirectToAction(nameof(Contact))); }
public async Task <IActionResult> EditPost(BackgroundImages image) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ModelState.AddModelError("", "Xaiş olunur düzgün doldurun."); return(View(image)); } BackgroundImages currentImages = await _context.BackgroundImages.FindAsync(image.Id); if (image.CupPhoto != null) { string computerPhoto = Path.Combine(_env.WebRootPath, "images", currentImages.CupPhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } if (image.CupPhoto.ContentType.Contains("image/")) { string filename = await image.CupPhoto.SaveWithoutFolderAsync(_env.WebRootPath); currentImages.CupPhotoURL = filename; } } if (image.HistoryPhoto != null) { string computerPhoto = Path.Combine(_env.WebRootPath, "images", currentImages.HistoryPhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } if (image.HistoryPhoto.ContentType.Contains("image/")) { string filename = await image.HistoryPhoto.SaveWithoutFolderAsync(_env.WebRootPath); currentImages.HistoryPhotoURL = filename; } } if (image.SquadPhoto != null) { string computerPhoto = Path.Combine(_env.WebRootPath, "images", currentImages.SquadPhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } if (image.SquadPhoto.ContentType.Contains("image/")) { string filename = await image.SquadPhoto.SaveWithoutFolderAsync(_env.WebRootPath); currentImages.SquadPhotoURL = filename; } } if (image.StadiumPhoto != null) { string computerPhoto = Path.Combine(_env.WebRootPath, "images", currentImages.StadiumPhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } if (image.StadiumPhoto.ContentType.Contains("image/")) { string filename = await image.StadiumPhoto.SaveWithoutFolderAsync(_env.WebRootPath); currentImages.StadiumPhotoURL = filename; } } await _context.SaveChangesAsync(); return(RedirectToAction("ImageIndex")); }