Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            AccountRepository addDb = new AccountRepository();

            if (ModelState.IsValid)
            {
                if (userRepository.CheckAccount(model.Email))
                {
                    ViewBag.Message = "your account was blocked";
                    return(View());
                }
                var user = new ApplicationUser {
                    FirstName = model.FirstName, UserName = model.Email, Surname = model.Surname, Email = model.Email, Gender = model.Gender, PhoneNumber = model.PhoneNumber, DateOfBirth = model.DateOfBirth, Country = model.Country, StreetAddress = model.StreetAddress, Sity = model.Sity, StatusBlockedUser = false, SendUnblock = false
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "user");
                    addDb.AddCardAndAccount(user.Id);
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            return(View(model));
        }