Exemplo n.º 1
0
        public Result <DataTableResult <UserTableModel> > GetGroupUsers(string roleId, DataTableRequest request)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <UserTableModel> >(ResultUtils.ToResultError(validationResult.Errors.ToList())));
            }

            BaseSpecification <RoleEntity> roleSpecification = new BaseSpecification <RoleEntity>();

            roleSpecification.AddFilter(x => x.Id == roleId);
            roleSpecification.AddFilter(x => x.Type == RoleTypes.Group);

            bool existResult = _roleRepository.Exist(roleSpecification);

            if (!existResult)
            {
                _logger.LogWarning($"GroupRole with id {roleId} does not exist");
                return(Result.Fail <DataTableResult <UserTableModel> >("no_role", "No Role"));
            }

            PaginationSpecification <GroupUserEntity, UserTableModel> baseSpecification = new PaginationSpecification <GroupUserEntity, UserTableModel>();

            baseSpecification.AddFilter(x => x.RoleId == roleId);
            baseSpecification.AddSelect(x => new UserTableModel(
                                            x.User.Id,
                                            x.User.UserName,
                                            x.Group.Name));

            if (!string.IsNullOrEmpty(request.Search))
            {
                string search = request.Search.ToUpper();

                baseSpecification.AddFilter(x =>
                                            x.User.Id.ToUpper().Contains(search) ||
                                            x.User.Email.ToUpper().Contains(search) ||
                                            x.User.UserName.ToUpper().Contains(search) ||
                                            x.User.FirstName.ToUpper().Contains(search) ||
                                            x.User.LastName.ToUpper().Contains(search));
            }
            baseSpecification.AppalyPaging(request.Start, request.Length);
            baseSpecification.AddInclude(x => x.User);

            PaginatedData <UserTableModel> paginationData = _groupUserRepository.GetPaginated(baseSpecification);

            DataTableResult <UserTableModel> result = new DataTableResult <UserTableModel>(
                draw: request.Draw,
                recordsTotal: paginationData.Count,
                recordsFilterd: paginationData.Count,
                error: null,
                data: paginationData.Data);

            return(Result.Ok(result));
        }
Exemplo n.º 2
0
        public Result <DataTableResult <PermissionTableModel> > Get(DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <PermissionTableModel> >(validationResult.Errors));
            }

            PaginationSpecification <PermissionEntity, PermissionTableModel> paginationSpecification =
                new PaginationSpecification <PermissionEntity, PermissionTableModel>();

            if (!string.IsNullOrEmpty(dataTableRequest.Search))
            {
                paginationSpecification.AddFilter(x => x.Name.ToUpper().Contains(dataTableRequest.Search.ToUpper()));
            }

            paginationSpecification.AddSelect(x => new PermissionTableModel(
                                                  x.Id,
                                                  x.Name));
            paginationSpecification.AppalyPaging(dataTableRequest.Start, dataTableRequest.Length);

            PaginatedData <PermissionTableModel> paginatedData = _permissionRepository.GetPaginated(paginationSpecification);

            DataTableResult <PermissionTableModel> dataTableResult = new DataTableResult <PermissionTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: paginatedData.Count,
                recordsFilterd: paginatedData.Count,
                error: null,
                data: paginatedData.Data);

            return(Result.Ok(dataTableResult));
        }
Exemplo n.º 3
0
        public Result <DataTableResult <SessionViewModel> > GetSessions(string userId, DataTableRequest request)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invlid DataTableRequest");
                return(Result.Fail <DataTableResult <SessionViewModel> >(validationResult.Errors));
            }

            PaginationSpecification <SessionEntity, SessionViewModel> specification = new PaginationSpecification <SessionEntity, SessionViewModel>();

            specification.AddFilter(x => x.UserId == userId);
            specification.AppalyPaging(request.Start, request.Length);
            specification.AddSelect(x => new SessionViewModel(
                                        x.Id,
                                        x.Ip,
                                        x._CreatedDate,
                                        x.LastAccess));

            PaginatedData <SessionViewModel> paginatedData = _sessionRepository.GetPaginated(specification);

            DataTableResult <SessionViewModel> dataTableResult = new DataTableResult <SessionViewModel>(
                draw: request.Draw,
                recordsTotal: paginatedData.Count,
                recordsFilterd: paginatedData.Count,
                error: null,
                data: paginatedData.Data);

            return(Result.Ok(dataTableResult));
        }
        public async Task <Result <DataTableResult <UserAttributeTableModel> > > Get(string userId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(DataTableRequest).Name} model");
                return(Result.Fail <DataTableResult <UserAttributeTableModel> >(validationResult.Errors));
            }

            PaginationSpecification <UserAttributeEntity, UserAttributeTableModel> paginationSpecification = new PaginationSpecification <UserAttributeEntity, UserAttributeTableModel>();

            paginationSpecification.AddFilter(x => x.UserId == userId);
            paginationSpecification.AddSelect(x => new UserAttributeTableModel(
                                                  x.Id,
                                                  x.Key,
                                                  x.Value));
            paginationSpecification.AppalyPaging(dataTableRequest.Start, dataTableRequest.Length);

            PaginatedData <UserAttributeTableModel> paginatedData = await _userAttributeRepository.GetPaginated(paginationSpecification);

            DataTableResult <UserAttributeTableModel> dataTableResult = new DataTableResult <UserAttributeTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: paginatedData.Count,
                recordsFilterd: paginatedData.Count,
                error: null,
                data: paginatedData.Data);

            return(Result.Ok(dataTableResult));
        }
        public Result <DataTableResult <GroupInviteTableModel> > Get(string groupId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableRequestValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <GroupInviteTableModel> >(validationResult.Errors));
            }

            PaginationSpecification <InviteEntity, GroupInviteTableModel> paginationSpecification =
                new PaginationSpecification <InviteEntity, GroupInviteTableModel>();

            paginationSpecification.AddFilter(x => x.GroupId == groupId);
            if (!string.IsNullOrEmpty(dataTableRequest.Search))
            {
                paginationSpecification.AddFilter(x => x.Email.ToUpper().Contains(dataTableRequest.Search.ToUpper()));
            }

            paginationSpecification.AddSelect(x => new GroupInviteTableModel(
                                                  x.Id,
                                                  x.Email,
                                                  x.GroupRole.Name,
                                                  x.Status.ToString(),
                                                  x.ExpiresAt.ToString(DateTimeFormats.DEFAULT_DATE_TIME_FORMAT)));

            paginationSpecification.AppalyPaging(dataTableRequest.Start, dataTableRequest.Length);

            PaginatedData <GroupInviteTableModel> paginatedData = _inviteRepository.GetPaginated(paginationSpecification);

            DataTableResult <GroupInviteTableModel> dataTableResult = new DataTableResult <GroupInviteTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: paginatedData.Count,
                recordsFilterd: paginatedData.Count,
                error: null,
                data: paginatedData.Data);

            return(Result.Ok(dataTableResult));
        }
        public Result <DataTableResult <RoleAssignmentTableModel> > Get(string roleId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <RoleAssignmentTableModel> >(validationResult.Errors));
            }

            PaginationSpecification <RoleEntity, RoleAssignmentTableModel> paginationSpecification =
                new PaginationSpecification <RoleEntity, RoleAssignmentTableModel>();

            paginationSpecification.AddFilter(x => x.Id != roleId);
            paginationSpecification.AddFilter(x => x.Type == Core.Data.Enums.Entity.RoleTypes.Group);
            if (!string.IsNullOrEmpty(dataTableRequest.Search))
            {
                paginationSpecification.AddFilter(x => x.NormalizedName.Contains(dataTableRequest.Search.ToUpper()));
            }

            paginationSpecification.AddSelect(x => new RoleAssignmentTableModel(
                                                  x.Id,
                                                  x.Name,
                                                  x.CanBeAssignedBy.Any(c => c.RoleId == roleId)));

            paginationSpecification.AppalyPaging(dataTableRequest.Start, dataTableRequest.Length);

            PaginatedData <RoleAssignmentTableModel> paginatedResult = _roleRepository.GetPaginated(paginationSpecification);

            DataTableResult <RoleAssignmentTableModel> dataTableResult = new DataTableResult <RoleAssignmentTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: paginatedResult.Count,
                recordsFilterd: paginatedResult.Count,
                error: null,
                data: paginatedResult.Data);

            return(Result.Ok(dataTableResult));
        }
Exemplo n.º 7
0
        public Result <DataTableResult <GroupUserTableModel> > Get(string id, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid DataTableRequest model");
                return(Result.Fail <DataTableResult <GroupUserTableModel> >(validationResult.Errors));
            }

            PaginationSpecification <GroupUserEntity, GroupUserTableModel> paginationSpecification = new PaginationSpecification <GroupUserEntity, GroupUserTableModel>();

            paginationSpecification.AddFilter(x => x.GroupId == id);

            if (!string.IsNullOrEmpty(dataTableRequest.Search))
            {
                paginationSpecification.AddFilter(x => x.User.NormalizedUserName.Contains(dataTableRequest.Search.ToUpper()));
            }

            paginationSpecification.AddSelect(x => new GroupUserTableModel(
                                                  x.Id,
                                                  x.User.Id,
                                                  x.User.UserName,
                                                  x.Role.Id,
                                                  x.Role.Name));
            paginationSpecification.AppalyPaging(dataTableRequest.Start, dataTableRequest.Length);

            PaginatedData <GroupUserTableModel> paginatedData = _groupUserRepository.GetPaginated(paginationSpecification);

            DataTableResult <GroupUserTableModel> dataTableResult = new DataTableResult <GroupUserTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: paginatedData.Count,
                recordsFilterd: paginatedData.Count,
                error: null,
                data: paginatedData.Data);

            return(Result.Ok(dataTableResult));
        }
Exemplo n.º 8
0
        public Result <DataTableResult <UserListViewModel> > GetAll(DataTableRequest request)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Result.Fail <DataTableResult <UserListViewModel> >(ResultUtils.ToResultError(validationResult.Errors.ToList())));
            }

            PaginationSpecification <AppUserEntity, UserListViewModel> baseSpecification = new PaginationSpecification <AppUserEntity, UserListViewModel>();

            if (!string.IsNullOrEmpty(request.Search))
            {
                string search = request.Search.ToUpper();

                baseSpecification.AddFilter(x =>
                                            x.Id.ToUpper().Contains(search) ||
                                            x.Email.ToUpper().Contains(search) ||
                                            x.UserName.ToUpper().Contains(search) ||
                                            x.FirstName.ToUpper().Contains(search) ||
                                            x.LastName.ToUpper().Contains(search));
            }

            baseSpecification.AppalyPaging(request.Start, request.Length);
            baseSpecification.AddSelect(x => new UserListViewModel(
                                            x.Id,
                                            x.UserName,
                                            x.Email,
                                            x.FirstName,
                                            x.LastName));

            PaginatedData <UserListViewModel> paginationData = _userRepository.GetPaginated(baseSpecification);

            DataTableResult <UserListViewModel> result = new DataTableResult <UserListViewModel>(
                draw: request.Draw,
                recordsTotal: paginationData.Count,
                recordsFilterd: paginationData.Count,
                error: null,
                data: paginationData.Data);

            return(Result.Ok(result));
        }
Exemplo n.º 9
0
        public Result <DataTableResult <RoleListViewModel> > GetAll(DataTableRequest request)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid DataTableRequest model");
                return(Result.Fail <DataTableResult <RoleListViewModel> >(ResultUtils.ToResultError(validationResult.Errors.ToList())));
            }

            PaginationSpecification <RoleEntity, RoleListViewModel> baseSpecification = new PaginationSpecification <RoleEntity, RoleListViewModel>();

            if (!string.IsNullOrEmpty(request.Search))
            {
                string search = request.Search.ToUpper();

                baseSpecification.AddFilter(x =>
                                            x.Id.ToUpper().Contains(search) ||
                                            x.Name.ToUpper().Contains(search));
            }

            baseSpecification.AppalyPaging(request.Start, request.Length);
            baseSpecification.AddSelect(x => new RoleListViewModel(
                                            x.Id,
                                            x.Name,
                                            x.Type.ToString()));

            PaginatedData <RoleListViewModel> pagedResult = _roleRepository.GetPaginated(baseSpecification);

            DataTableResult <RoleListViewModel> result = new DataTableResult <RoleListViewModel>(
                draw: request.Draw,
                recordsTotal: pagedResult.Count,
                recordsFilterd: pagedResult.Count,
                error: null,
                data: pagedResult.Data);

            return(Result.Ok(result));
        }