public SnippetsViewModel EditSnippet(SnippetsViewModel model, int id) { Snippet snippet = db.Snippets.Find(id); CategorySnippetAssociations snippetCategoryAssociation = db.CategorySnippetAssociations.Find(id); //If we have new notes being passed to the controller if (model.NoteList.Any() && model.NoteList != null) { //Remove all of the previous notes List <Note> removeNotes = (from n in db.Notes where n.NoteSnippetId == id select n).ToList(); for (int i = 0; i < removeNotes.Count(); i++) { db.Notes.Remove(removeNotes[i]); } //Add all the new notes for (int i = 0; i < model.NoteCount; i++) { Note newNote = new Note { NoteSnippetId = snippet.SnippetId, NoteTitle = model.NoteList[i].NoteTitle, NoteContent = model.NoteList[i].NoteContent, NoteCount = model.NoteCount }; db.Notes.Add(newNote); } } snippet.SnippetName = Sanitizer.GetSafeHtmlFragment(model.SnippetName); snippet.SnippetContent = model.SnippetContent; snippet.SnippetDescription = model.SnippetDescription; snippet.ReferenceURL = Sanitizer.GetSafeHtmlFragment(model.ReferenceUrl); snippet.SnippetLanguage = Sanitizer.GetSafeHtmlFragment(model.SnippetLanguage); snippetCategoryAssociation.CategoryAssociationId = model.SelectedCategoryId; db.Entry(snippetCategoryAssociation).State = EntityState.Modified; db.Entry(snippet).State = EntityState.Modified; db.SaveChanges(); return(model); }
public ActionResult Edit([Bind(Include = "Id,ProjectProjectId,CategoryCategoryId")] ProjectCategories projectCategories) { if (ModelState.IsValid) { db.Entry(projectCategories).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectProjectId = new SelectList(db.Projects, "ProjectId", "ProjectTitle", projectCategories.ProjectProjectId); ViewBag.CategoryCategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", projectCategories.CategoryCategoryId); return(View(projectCategories)); }
public ActionResult Edit([Bind(Include = "ProjectId,ProjectTitle,ProjectDescription")] Project project) { if (ModelState.IsValid) { db.Entry(project).State = EntityState.Modified; db.SaveChanges(); TempData["UpdateMessage"] = "<div class='alert alert-info w-fade-out'>Project Successfully Updated!</div>"; return(RedirectToAction("Index")); } return(View(project)); }