Пример #1
0
        public async Task <ActionResult> Register(RegisterViewModel r)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.FirstOrDefault(u => u.UserName == r.UserName || u.EmailAddress == r.EmailAddress);
                if (user != null)
                {
                    ModelState.AddModelError("", "Username or Email address has been registered, please sign in or change another");
                    return(View());
                }
                var newUser = new User();
                db.Users.Add(RegisterViewModel.ConvertToUser(r, newUser));
                if (EmailUtil.RegisterConfirmation(newUser))
                {
                    TempData["Msg"] = "alert('Congratulations! You have been registered successfully! " +
                                      "Please click the validation link in your Email box to validate your account.')";
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("SignIn", "Users"));
            }

            return(View());
        }