public IActionResult Add(Note model) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } model.UserNo = int.Parse(HttpContext.Session.GetInt32("USER_LOGIN_KEY").ToString()); if (ModelState.IsValid) { using (var db = new AspNetNoteContext()) { db.Notes.Add(model); var result = db.SaveChanges(); //Commit if (result > 0) { return(Redirect("Index")); } } ModelState.AddModelError(string.Empty, "Cannot add the content"); } return(View(model)); }
public IActionResult Register(User model) { if (ModelState.IsValid) { using (var db = new AspNetNoteContext()) { db.Users.Add(model); //upload data to memory db.SaveChanges(); //save data to sql table } return(RedirectToAction("Index", "Home")); } return(View(model)); }