public async Task <OperationResultResponse <RoleResponse> > ExecuteAsync(GetRoleFilter filter)
        {
            OperationResultResponse <RoleResponse> result = new();

            (DbRole role, List <DbUser> users, List <DbRightsLocalization> rights) = await _roleRepository.GetAsync(filter);

            if (role == null)
            {
                _httpContextAccessor.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;

                return(result);
            }

            List <Guid> usersIds = users?.Select(u => u.UserId).ToList();

            usersIds.Add(role.CreatedBy);

            if (role.ModifiedBy.HasValue)
            {
                usersIds.Add(role.ModifiedBy.Value);
            }

            List <UserData> usersDatas = await GetUsersAsync(usersIds, result.Errors);

            result.Body = _roleResponseMapper.Map(role, rights, usersDatas);

            return(result);
        }
Ejemplo n.º 2
0
 public async Task <OperationResultResponse <RoleResponse> > GetAsync(
     [FromServices] IGetRoleCommand command,
     [FromQuery] GetRoleFilter filter)
 {
     return(await command.ExecuteAsync(filter));
 }
Ejemplo n.º 3
0
        public async Task <(DbRole role, List <DbUser> users, List <DbRightsLocalization> rights)> GetAsync(GetRoleFilter filter)
        {
            return((await
                        (from role in _provider.Roles
                        join roleLocalization in _provider.RolesLocalizations on role.Id equals roleLocalization.RoleId
                        join right in _provider.RoleRights on role.Id equals right.RoleId
                        join rightLocalization in _provider.RightsLocalizations on right.RightId equals rightLocalization.RightId
                        join user in _provider.Users on role.Id equals user.RoleId into Users
                        from user in Users.DefaultIfEmpty()
                        where role.Id == filter.RoleId &&
                        (roleLocalization.Locale == filter.Locale || roleLocalization.Locale == null) &&
                        (rightLocalization.Locale == filter.Locale || rightLocalization.Locale == null)
                        select new
            {
                Role = role,
                RoleLocalization = roleLocalization,
                RightLocalization = rightLocalization,
                User = user
            }).ToListAsync()).AsEnumerable().GroupBy(r => r.Role.Id)
                   .Select(x =>
            {
                DbRole role = x.Select(x => x.Role).FirstOrDefault();
                role.RoleLocalizations = x.Select(x => x.RoleLocalization).Where(x => x != null).GroupBy(x => x.Id).Select(x => x.First()).ToList();

                return (role, x.Select(x => x.User).Where(u => u != null).ToList(), x.Select(x => x.RightLocalization).ToList());
            }).FirstOrDefault());
        }