public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AdventureTime_Story story = storyRepo.Stories.FirstOrDefault(s => s.StoryID == id); if (story.StoryID != id) { return(HttpNotFound()); } return(View(story)); }
public void DeleteStory(AdventureTime_Story story) { foreach (var paragragh in context.Paragraphs) { if (story.StoryID == paragragh.StoryID) { context.Paragraphs.Remove(paragragh); context.SaveChanges(); } } context.Stories.Remove(story); context.SaveChanges(); }
public ActionResult Edit(AdventureTime_Story story) { try { if (ModelState.IsValid) { storyRepo.SaveStory(story); return(RedirectToAction("List")); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Story", "Edit"))); } return(View(story)); }
// Save new stories or make changes to existing stories public void SaveStory(AdventureTime_Story story) { // Check to see if story exists if (story.StoryID == 0) { context.Stories.Add(story); } else { // Retrieve existing story and rewrite any changes AdventureTime_Story dbEntry = context.Stories.Find(story.StoryID); if (dbEntry != null) { dbEntry.StoryID = story.StoryID; dbEntry.StoryTitle = story.StoryTitle; dbEntry.StoryGenre = story.StoryGenre; dbEntry.AuthorID = story.AuthorID; dbEntry.DateCreated = story.DateCreated; } } context.SaveChanges(); }
public ViewResult Edit(int id) { AdventureTime_Story story = storyRepo.Stories.FirstOrDefault(s => s.StoryID == id); return(View(story)); }
public ActionResult Delete(AdventureTime_Story story) { storyRepo.DeleteStory(story); return(View("List")); }