public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new {UserSurname = model.UserSurname, UserAdress = model.UserAdress, UserEmail = model.UserEmail});
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, "question", "answer", true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         var dao = new UserDao();
         if (dao.CheckUserName(model.UserName))
         {
             ModelState.AddModelError("", "Tên đăng nhập đã tồn tại");
         }
         else if (dao.CheckEmail(model.Email))
         {
             ModelState.AddModelError("", "Email đã tồn tại");
         }
         else
         {
             var user = new User();
             user.Name = model.Name;
             user.Password = Encryptor.MD5Hash(model.Password);
             user.Phone = model.Phone;
             user.Email = model.Email;
             user.CreatedDate = DateTime.Now;
             user.Status = true;
             if (!string.IsNullOrEmpty(model.ProvinceID))
             {
                 user.ProvinceID = int.Parse(model.ProvinceID);
             }
             if (!string.IsNullOrEmpty(model.DistrictID))
             {
                 user.DistrictID = int.Parse(model.DistrictID);
             }
             var result = dao.Insert(user);
             if (result > 0)
             {
                 ViewBag.Success = "Đăng ký thành công";
                 model = new RegisterModel();
             }
             else
             {
                 ModelState.AddModelError("", "Đăng ký không thành công");
             }
         }
     }
     return View(model);
 }