Esempio n. 1
0
        /// <summary>
        /// Creates the user profile.
        /// </summary>
        /// <param name="profileModel">The profile model.</param>
        /// <param name="accountModel">The account model.</param>
        /// <returns></returns>
        /// <exception cref="FormatException">
        /// Email address invalid
        /// or
        /// Phone number invalid
        /// or
        /// Email existed
        /// </exception>
        public async Task <bool> CreateUserProfile(UserRegisterModel profileModel
                                                   , UserAccountCreateModel accountModel)
        {
            if (!ValidateUtils.IsMail(profileModel.Email))
            {
                throw new FormatException("Email address invalid");
            }

            var query = _userProfileRepository.GetManyAsNoTracking(x => x.Email.Equals(profileModel.Email));

            if (query.ToList().Count != 0)
            {
                throw new FormatException("Email existed");
            }
            var userProfile = _userProfileRepository.Insert(new UserProfile
            {
                Email     = profileModel.Email,
                FirstName = profileModel.FirstName,
                LastName  = profileModel.LastName,
                Phone     = profileModel.Phone,
                Address   = profileModel.Address
            });

            return(await _userAccountService.CreateUserAccount(accountModel, userProfile.Entity.UserProfileId));
        }
        public NewAccountViewModel(IUserAccountService userAccountService, IMvxNavigationService mvxNavigationService)
        {
            _userAccountService   = userAccountService;
            _mvxNavigationService = mvxNavigationService;
            Model = new UserAccountModel();

            this.CreateAccountCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                Model.Validade();
                await _userAccountService.CreateUserAccount(Model);
                await _mvxNavigationService.Navigate <AccountCreatedViewModel>();
                await _mvxNavigationService.Close(this);
            },
                                                                       this.WhenAnyValue(
                                                                           x => x.Model.FirstName,
                                                                           x => x.Model.LastName,
                                                                           x => x.Model.Username,
                                                                           x => x.Model.Password,
                                                                           x => x.Model.PhoneNumber,
                                                                           (firstName, lastName, username, password, phoneNumber) =>
                                                                           !string.IsNullOrEmpty(Model.FirstName) &&
                                                                           !string.IsNullOrEmpty(Model.LastName) &&
                                                                           !string.IsNullOrEmpty(Model.Username) &&
                                                                           !string.IsNullOrEmpty(Model.Password) &&
                                                                           !string.IsNullOrEmpty(Model.PhoneNumber)));
        }
Esempio n. 3
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User {
                    Email = model.Email, UserName = model.Email, FullName = model.FullName
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, false);

                    var currentUser = _userManager.Users.FirstOrDefault(x => x.Email == model.Email);
                    _userAccountService.CreateUserAccount(new UserAccount {
                        User = currentUser
                    });
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
Esempio n. 4
0
 public IHttpActionResult CreateUserAccount([FromBody] UserAccount userAccount)
 {
     return(Ok(_userAccountService.CreateUserAccount(userAccount)));
 }