Beispiel #1
0
        public User Register(RegisterModel register)
        {
            if (register == null)
            {
                throw new ArgumentNullException("user");
            }

            User user = new User();
            user.first_name = register.FirstName;
            user.last_name = register.LastName;
            user.username = register.UserName;
            user.password = CryptoUtil.ComputeHash(register.Password);

            using (var db = new LocalNewsDBEntities())
            {
                db.Users.Add(user);
                db.SaveChanges();
            }
            loginHistoryBll.Add(user.user_id, LocalNewsConstant.User_Status_New_User);
            return user;
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    userBll.Register(model);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }