Exemple #1
0
        protected virtual async Task UpdateUserAsync(CreateOrUpdateUserInput input)
        {
            FuelWerx.Authorization.Users.UserManager userManager = this.UserManager;
            long?id   = input.User.Id;
            User user = await userManager.FindByIdAsync(id.Value);

            input.User.MapTo <UserEditDto, User>(user);
            if (!input.User.Password.IsNullOrEmpty())
            {
                IdentityResult identityResult = await this.UserManager.ChangePasswordAsync(user, input.User.Password);

                this.CheckErrors(identityResult);
            }
            this.CheckErrors(await this.UserManager.UpdateAsync(user));
            IRepository <Customer, long> repository = this._customerRepository;
            List <Customer> allListAsync            = await repository.GetAllListAsync((Customer m) => (int?)m.TenantId == user.TenantId && m.UserId.HasValue && m.UserId == (long?)user.Id);

            bool               flag        = allListAsync.Any <Customer>();
            string             str         = this.L("KeyName_CustomersRole");
            IRepository <Role> repository1 = this._roleRepository;
            List <Role>        roles       = await repository1.GetAllListAsync((Role m) => m.TenantId == (int?)((this.AbpSession.ImpersonatorTenantId.HasValue ? this.AbpSession.ImpersonatorTenantId.Value : this.AbpSession.TenantId.Value)) && m.DisplayName == str);

            List <Role>    roles1          = roles;
            IdentityResult identityResult1 = await this.UserManager.SetRoles(user, input.AssignedRoleNames);

            this.CheckErrors(identityResult1);
            if (!flag && roles1.Count == 1 && input.AssignedRoleNames.Contains <string>(roles1[0].Name))
            {
                Customer customer = new Customer()
                {
                    AllowBillPay = false,
                    BusinessName = null,
                    FirstName    = user.Name,
                    LastName     = user.Surname,
                    Email        = user.EmailAddress,
                    IsActive     = true,
                    PaymentAssistanceParticipant = false
                };
                id = null;
                customer.TitleId  = id;
                customer.UserId   = new long?(user.Id);
                customer.TenantId = user.TenantId.Value;
                await this._customerRepository.InsertAsync(customer);

                await this.CurrentUnitOfWork.SaveChangesAsync();
            }
            if (input.SendActivationEmail)
            {
                user.SetNewEmailConfirmationCode();
                await this._userEmailer.SendEmailActivationLinkAsync(user, input.User.Password);
            }
        }
Exemple #2
0
        public async Task <GetUserForEditOutput> GetUserForEdit(NullableIdInput <long> input)
        {
            IQueryable <Role>        roles       = this._roleManager.Roles;
            IOrderedQueryable <Role> displayName =
                from r in roles
                orderby r.DisplayName
                select r;

            UserRoleDto[] arrayAsync = await(
                from r in displayName
                select new UserRoleDto()
            {
                RoleId          = r.Id,
                RoleName        = r.Name,
                RoleDisplayName = r.DisplayName
            }).ToArrayAsync <UserRoleDto>();
            UserRoleDto[]        userRoleDtoArray     = arrayAsync;
            GetUserForEditOutput getUserForEditOutput = new GetUserForEditOutput()
            {
                Roles = userRoleDtoArray
            };

            if (input.Id.HasValue)
            {
                FuelWerx.Authorization.Users.UserManager userManager = this.UserManager;
                long?id            = input.Id;
                User userByIdAsync = await userManager.GetUserByIdAsync(id.Value);

                getUserForEditOutput.User             = userByIdAsync.MapTo <UserEditDto>();
                getUserForEditOutput.ProfilePictureId = userByIdAsync.ProfilePictureId;
                IRepository <UserSettingData, long> repository = this._userSettingDataRepository;
                UserSettingData userSettingDatum = await repository.FirstOrDefaultAsync((UserSettingData m) => m.UserId == userByIdAsync.Id);

                UserSettingData userSettingDatum1 = userSettingDatum;
                if (userSettingDatum1 == null)
                {
                    GetUserForEditOutput getUserForEditOutput1 = getUserForEditOutput;
                    UserSettingData      userSettingDatum2     = new UserSettingData()
                    {
                        UserId = userByIdAsync.Id
                    };
                    getUserForEditOutput1.UserSettingData = userSettingDatum2.MapTo <UserSettingDataEditDto>();
                }
                else
                {
                    getUserForEditOutput.UserSettingData = userSettingDatum1.MapTo <UserSettingDataEditDto>();
                }
                UserRoleDto[] userRoleDtoArray1 = userRoleDtoArray;
                for (int i = 0; i < (int)userRoleDtoArray1.Length; i++)
                {
                    UserRoleDto userRoleDto  = userRoleDtoArray1[i];
                    UserRoleDto userRoleDto1 = userRoleDto;
                    FuelWerx.Authorization.Users.UserManager userManager1 = this.UserManager;
                    id = input.Id;
                    bool flag = await userManager1.IsInRoleAsync(id.Value, userRoleDto.RoleName);

                    userRoleDto1.IsAssigned = flag;
                    userRoleDto1            = null;
                }
                userRoleDtoArray1 = null;
            }
            else
            {
                GetUserForEditOutput getUserForEditOutput2 = getUserForEditOutput;
                UserEditDto          userEditDto           = new UserEditDto()
                {
                    IsActive = true,
                    ShouldChangePasswordOnNextLogin = true
                };
                getUserForEditOutput2.User           = userEditDto;
                getUserForEditOutput.UserSettingData = new UserSettingDataEditDto()
                {
                    UserId = (long)0
                };
                IQueryable <Role> roles1    = this._roleManager.Roles;
                List <Role>       listAsync = await(
                    from r in roles1
                    where r.IsDefault
                    select r).ToListAsync <Role>();
                foreach (Role role in listAsync)
                {
                    UserRoleDto userRoleDto2 = userRoleDtoArray.FirstOrDefault <UserRoleDto>((UserRoleDto ur) => ur.RoleName == role.Name);
                    if (userRoleDto2 == null)
                    {
                        continue;
                    }
                    userRoleDto2.IsAssigned = true;
                }
            }
            return(getUserForEditOutput);
        }