Ejemplo n.º 1
0
        public IActionResult Register(User model)
        {
            return(RedirectToAction("Error", "Account"));

            if (ModelState.IsValid)
            {
                using (var db = new WebNoteDbContext())    // using keywork : Disposiable work [ ex) try ~ finally { Dispose() } ]
                {
                    db.Users.Add(model);                   // ride on memory
                    db.SaveChanges();                      // real database commit
                }
                return(RedirectToAction("Index", "Home")); // refresh other page
            }

            return(View(model));
        }
        public IActionResult Add(Note model)
        {
            if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null)
            {
                // not in login
                return(RedirectToAction("Login", "Account"));
            }
            model.UserNo = int.Parse(HttpContext.Session.GetInt32("USER_LOGIN_KEY").ToString());

            if (ModelState.IsValid)
            {
                using (var db = new WebNoteDbContext())
                {
                    db.Notes.Add(model);

                    if (db.SaveChanges() > 0)
                    {
                        return(Redirect("Index"));
                    }
                }
                ModelState.AddModelError(string.Empty, "Can't save note.");
            }
            return(View(model));
        }