public ActionResult CreateNote(Note n) { try { if (String.IsNullOrEmpty(Request.Form["Content"].ToString())) { User user = userService.GetById(Int32.Parse(Session["LogedUserID"].ToString())); noteService.Add(user, new Note { Content = "Empty", CreateDate = DateTime.Now }); } else { User user = userService.GetById(Int32.Parse(Session["LogedUserID"].ToString())); noteService.Add(user, new Note { Content = Request.Form["Content"], CreateDate = DateTime.Now }); } noteService.Save(); return RedirectToAction("ShowNotes", "Note"); } catch (NullReferenceException) { return RedirectToAction("ErrorMessage", "User"); } catch (SqlException) { return RedirectToAction("ErrorMessage", "User"); } }
public void Update(Note note) { db.Entry(note).State = EntityState.Modified; }
public void Add(User user, Note note) { User findUser = db.Users.Find(user.UserId); findUser.Notes.Add(note); }