Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Id,title,content,status_")] news news)
        {
            if (ModelState.IsValid)
            {
                db.news.Add(news);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(news));
        }
Esempio n. 2
0
        public ActionResult register(User user)
        {
            if (ModelState.IsValid)

            {
                var confirm = 0;
                using (mydatabase adduser = new mydatabase())
                {
                    if (user.password == user.confirmpassword)
                    {
                        var check = adduser.Users.Where(u => u.username == user.username).Count();

                        if (check == 0)
                        {
                            adduser.Users.Add(user);
                            adduser.SaveChanges();
                            confirm = 1;
                        }
                        else
                        {
                            ModelState.AddModelError("", "Username exists!!!");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Password and Confirm password is not same!!!");
                    }
                }
                if (confirm == 1)
                {
                    ModelState.Clear();
                    ViewBag.Message = user.username + " đăng kí thành công!";
                    return(RedirectToAction("login"));
                }
            }
            return(View());
        }