Example #1
0
        private async Task <User> CheckUserAsync(
            string _userName,
            string _password,
            string _firtsName,
            string _lastName,
            string _phoneNumber,
            string _address,
            string _cityDescription,
            string _role)
        {
            #region Admin User / Role

            var user = await this.iUserHelper.GetUserByEmailAsync(
                _userName);

            if (user == null)
            {
                user = new User
                {
                    FirstName   = _firtsName,
                    LastName    = _lastName,
                    Email       = _userName,
                    UserName    = _userName,
                    PhoneNumber = _phoneNumber,
                    Address     = _address,
                    CityId      = MethodsHelper.GetCityIdByDescription(_cityDescription, context),
                    City        = MethodsHelper.GetCityByDescription(_cityDescription, context),
                };

                var result = await this.iUserHelper.AddUserAsync(
                    user,
                    _password);

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Could not create the user in seeder");
                }

                await this.iUserHelper.AddUserToRoleAsync(
                    user,
                    _role);
            }

            //  var chanePassword = await this.iUserHelper.ChangePasswordAsync(user, "123456", "Chej5654.");

            var isInRole = await this.iUserHelper.IsUserInRoleAsync(
                user,
                _role);

            if (!isInRole)
            {
                await this.iUserHelper.AddUserToRoleAsync(
                    user,
                    _role);
            }

            #region Confirm Email

            var token = await this.iUserHelper.GenerateEmailConfirmationTokenAsync(user);

            await this.iUserHelper.ConfirmEmailAsync(user, token);

            #endregion Confirm Email

            #endregion Admin User / Role

            return(user);
        }