예제 #1
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);
        }