Beispiel #1
0
        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")); // 동일한컨트롤러로갈때
                    }
                }
                ModelState.AddModelError(string.Empty, "게시물을 저장할수 없습니다.");
            }
            return(View(model));
        }
 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));
 }