public IActionResult Register(User model) { if (ModelState.IsValid) { using (var db = new AspNetDbContext()) { db.Users.Add(model); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); } return(View(model)); }
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 AspNetDbContext()) { db.Notes.Add(model); if (db.SaveChanges() > 0) //commit 결과가 성공일 경우 { return(Redirect("Index")); //동일한 컨트롤러 내의 리다이렉트는 toaction안해도 ㅇㅋ } ModelState.AddModelError(string.Empty, "게시물 저장 불가"); } } return(View(model)); }