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 AspnetNoteDbcontext())
                {
                    db.Notes.Add(model);

                    //var result = db.SaveChanges();

                    if (db.SaveChanges() > 0)
                    {
                        return(Redirect("Index"));
                    }

                    //return RedirectToAction("Index", "Home");
                }

                ModelState.AddModelError(string.Empty, "게시물을 저장할 수 없습니다.");
            }
            return(View(model));
        }
Beispiel #2
0
 public IActionResult Register(User model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new AspnetNoteDbcontext())
         {
             db.Users.Add(model);
             db.SaveChanges();
         }
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }