public async Task <IActionResult> Create([Bind("Title,Description,IsActive,PhotoID,CinemaID")] PhotoGal photo) { PhotoDBExist(photo.Title, photo.CinemaID); if (ModelState.IsValid) { try { db.Gallery.Add(photo); await db.SaveChangesAsync(); TempData["Status"] = "A new photo named " + photo.Title + " has been added to the gallery."; TempData["Color"] = "success"; return(RedirectToAction(nameof(Index))); } catch (Exception) { TempData["Status"] = "We're sorry, an unexpected error has been accured." + Environment.NewLine + "If you keep getting this error please contact system administrator."; TempData["Color"] = "danger"; ViewData["CinemaID"] = new SelectList(db.Cinemas, "ID", "Name", photo.CinemaID); ViewData["PhotoID"] = new SelectList(db.Images.Where(i => i.Category == ImageCategory.Gallery), "ID", "Name", photo.PhotoID); return(View(photo)); } } ViewData["CinemaID"] = new SelectList(db.Cinemas, "ID", "Name", photo.CinemaID); ViewData["PhotoID"] = new SelectList(db.Images.Where(i => i.Category == ImageCategory.Gallery), "ID", "Name", photo.PhotoID); return(View(photo)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Description,IsActive,PhotoID,CinemaID")] PhotoGal photo) { if (id != photo.ID) { TempData["Status"] = "We're sorry, an unexpected error has been accured." + Environment.NewLine + "If you keep getting this error please contact system administrator."; TempData["Color"] = "danger"; return(RedirectToAction(nameof(Index))); } PhotoDBExist(photo.Title, photo.CinemaID, photo.ID); if (ModelState.IsValid) { try { db.Gallery.Update(photo); await db.SaveChangesAsync(); TempData["Status"] = "The changes you made to the photo have been saved!"; TempData["Color"] = "success"; } catch (DbUpdateConcurrencyException) { if (!PhotoGalExists(photo.ID)) { return(RedirectToAction("Page404", "Home")); } TempData["Status"] = "We're sorry, an unexpected error has been accured." + Environment.NewLine + "If you keep getting this error please contact system administrator."; TempData["Color"] = "danger"; return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Info), new { id = photo.ID })); } ViewData["CinemaID"] = new SelectList(db.Cinemas, "ID", "Name", photo.CinemaID); ViewData["PhotoID"] = new SelectList(db.Images.Where(i => i.Category == ImageCategory.Gallery), "ID", "Name", photo.PhotoID); return(View(photo)); }