コード例 #1
0
        public async Task <IActionResult> UserRolesDelete(TUserDtoKey id, TRoleDtoKey roleId)
        {
            await _identityService.ExistsUserAsync(id.ToString());

            await _identityService.ExistsRoleAsync(roleId.ToString());

            var userDto = await _identityService.GetUserAsync(id.ToString());

            var roles = await _identityService.GetRolesAsync();

            var rolesDto = new UserRolesDto <TRoleDto, TUserDtoKey, TRoleDtoKey>
            {
                UserId    = id,
                RolesList = roles.Select(x => new SelectItemDto(x.Id.ToString(), x.Name)).ToList(),
                RoleId    = roleId,
                UserName  = userDto.UserName
            };

            return(View(rolesDto));
        }
コード例 #2
0
        public ActionResult UserRolesGridViewPartialUpdate(UserRolesDto item)
        {
            var model = db.UserRoles;

            if (ModelState.IsValid)
            {
                try
                {
                    var userRole = db.UserRoles.Where(c => c.ObjId == item.ObjId).SingleOrDefault();

                    if (userRole != null)
                    {
                        this.UpdateModel(userRole);
                        db.SaveChanges();
                    }

                    else
                    {
                        userRole.RoleId = item.RoleId;
                        model.Attach(userRole);
                        db.SaveChanges();
                        ;
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            var modelReturn = GetUserRolesDto(item.UserId.ToString());

            return(PartialView("_UserRoles", modelReturn));
        }
コード例 #3
0
        public async Task <IdentityResult> DeleteUserRoleAsync(UserRolesDto role)
        {
            var identityResult = await _identityRepository.DeleteUserRoleAsync(role.UserId, role.RoleId);

            return(HandleIdentityError(identityResult, _identityServiceResources.UserRoleDeleteFailed().Description, _identityServiceResources.IdentityErrorKey().Description, role));
        }
コード例 #4
0
        public async Task <BaseApiResponse> GetUserRoles(string userId)
        {
            try
            {
                if (userId == null)
                {
                    return(BaseApiResponseHelper.GenerateApiResponse(true, "get roles for user", null, new List <string> {
                        $"User ID is null."
                    }));
                }

                var user = await _userManager.FindByIdAsync(userId);

                if (user == null)
                {
                    return(BaseApiResponseHelper.GenerateApiResponse(true, "get roles for user", null,
                                                                     new List <string> {
                        $"User ID {userId} did not match any users."
                    }));
                }

                var listUserRolesDto = new List <UserRolesDto>();

                foreach (var role in await _roleManager.Roles.ToListAsync())
                {
                    var userRolesDto = new UserRolesDto
                    {
                        RoleName = role.Name
                    };

                    if (await _userManager.IsInRoleAsync(user, role.Name))
                    {
                        userRolesDto.Selected = true;
                    }
                    else
                    {
                        userRolesDto.Selected = false;
                    }

                    listUserRolesDto.Add(userRolesDto);
                }

                var data = new UserRolesForEditDto
                {
                    UserId    = user.Id,
                    Username  = user.UserName,
                    Email     = user.Email,
                    UserRoles = listUserRolesDto
                };

                return(BaseApiResponseHelper.GenerateApiResponse(true, "Get roles for user", new List <UserRolesForEditDto> {
                    data
                }, null));
            }
            catch (Exception ex)
            {
                return(BaseApiResponseHelper.GenerateApiResponse(false, "get roles for user", null, new List <string> {
                    $"{ex.Message}."
                }));
            }
        }
コード例 #5
0
 public static UserRole FromDto(UserRolesDto dto) => dto.To <UserRole>();
コード例 #6
0
        public async Task <int> AssignRoleToUser(UserRolesDto dto)
        {
            var userRole = _mapper.Map <UserRolesDto, UserRoles>(dto);

            return(await _userRepository.AssignRoleToUser(userRole));
        }
コード例 #7
0
        public UserRolesDto Update(UserRolesDto entity)
        {
            var model = Mapper.Map <UserRoles>(entity);

            return(Mapper.Map <UserRolesDto>(_userRolesDal.Update(model)));
        }
コード例 #8
0
        public UserRolesDto Add(UserRolesDto entity)
        {
            var model = Mapper.Map <UserRoles>(entity);

            return(Mapper.Map <UserRolesDto>(_userRolesDal.Add(model)));
        }
コード例 #9
0
 public void Delete(UserRolesDto entity)
 {
     _userRolesDal.Delete(Mapper.Map <UserRoles>(entity));
 }
コード例 #10
0
 public UserRolesDto UpdateUserRoleList(UserRolesDto roles)
 {
     throw new NotImplementedException();
 }