Beispiel #1
0
        public async Task <Result <DataTableResult <AuditAdminTableModel> > > Get(DataTableRequest dataTableRequest, AuditTableRequest auditTableRequest)
        {
            ValidationResult dataTableValidationResult = _dataTableRequestValidator.Validate(dataTableRequest);

            if (!dataTableValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >(dataTableValidationResult.ToResultError()));
            }

            if (auditTableRequest == null)
            {
                _logger.LogWarning($"AuditTable request can not be null");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >("can_not_be_null", "Can not be null"));
            }

            ValidationResult auditTableRequestValidationResult = _auditTableRequestValidator.Validate(auditTableRequest);

            if (!auditTableRequestValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(AuditTableRequest)} model");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >(auditTableRequestValidationResult.ToResultError()));
            }

            IBaseSpecificationBuilder <AuditEntity> baseSpecification = SpecificationBuilder
                                                                        .Create <AuditEntity>()
                                                                        .WithActionType(auditTableRequest.ActionType)
                                                                        .WithObjectType(auditTableRequest.ObjectType)
                                                                        .WithObjectIdentifier(auditTableRequest.ObjectIdentifier)
                                                                        .WithSubjectType(auditTableRequest.SubjectType)
                                                                        .WithSubjectIdentifier(auditTableRequest.SubjectIdentifier)
                                                                        .WithResourceName(auditTableRequest.ResourceName)
                                                                        .InRange(auditTableRequest.From, auditTableRequest.To);

            IBaseSpecification <AuditEntity, AuditAdminTableModel> selectSpecification = baseSpecification
                                                                                         .OrderBy(x => x.Created, auditTableRequest.OrderBy.Value)
                                                                                         .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                         .Select(x => new AuditAdminTableModel(
                                                                                                     x.Id,
                                                                                                     x.ActionType.GetDescription(),
                                                                                                     x.ObjectType,
                                                                                                     x.ResourceName,
                                                                                                     x.SubjectType.GetDescription(),
                                                                                                     x.SubjectIdentifier,
                                                                                                     x.Created.ToString("o")))
                                                                                         .Build();

            int auditCount = await _auditDAO.Count(baseSpecification.Build());

            List <AuditAdminTableModel> audits = await _auditDAO.Get(selectSpecification);

            DataTableResult <AuditAdminTableModel> dataTableResult = new DataTableResult <AuditAdminTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: auditCount,
                recordsFiltered: auditCount,
                error: null,
                data: audits);

            return(Result.Ok(dataTableResult));
        }
        private async Task <Result <Select2Result <Select2Item> > > GetPaginatedSelect2Result <TResult>(
            ISelectSpecificationBuilder <AuditEntity, TResult> specificationBuilder,
            Select2Request select2Request)
        {
            int count = await _auditDAO.Count(specificationBuilder.Build());

            var selectSpecification = specificationBuilder
                                      .Paginate(select2Request.GetPageStart(), select2Request.GetPageLenght())
                                      .Build();

            List <TResult> objectTypes = await _auditDAO.Get(selectSpecification);

            Select2Result <Select2Item> select2Result = new Select2Result <Select2Item>(
                objectTypes
                .Select(x => new Select2Item(
                            id: x?.ToString(),
                            text: x?.ToString()))
                .ToList(),
                pagination: select2Request.IsMore(count));

            return(Result.Ok(select2Result));
        }
        public async Task <Result <DataTableResult <AuditTableModel> > > Get(DataTableRequest dataTableRequest, AuditTableRequest auditTableRequest)
        {
            ValidationResult validationResult = _dataTableRequestValidator.Validate(dataTableRequest);

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

            ValidationResult auditTabeValidationResult = _auditTableRequestValidator.Validate(auditTableRequest);

            if (!auditTabeValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(AuditTableRequest).Name} model");
                return(Result.Fail <DataTableResult <AuditTableModel> >(validationResult.ToResultError()));
            }

            IBaseSpecificationBuilder <AuditEntity> baseSpecification = SpecificationBuilder
                                                                        .Create <AuditEntity>()
                                                                        .WithActionType(auditTableRequest.ActionType)
                                                                        .InRange(auditTableRequest.From?.UtcDateTime, auditTableRequest.To?.UtcDateTime)
                                                                        .WithUser(_httpContextAccessor.HttpContext.User.GetUserId());

            IBaseSpecification <AuditEntity, AuditTableModel> selectSpecification = baseSpecification
                                                                                    .OrderBy(x => x.Created, auditTableRequest.OrderBy.Value)
                                                                                    .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                    .Select(x => new AuditTableModel(
                                                                                                x.Id,
                                                                                                x.ActionType.GetDescription(),
                                                                                                x.ResourceName,
                                                                                                x.Created.ToString("o")))
                                                                                    .Build();

            int auditsCount = await _auditDAO.Count(baseSpecification.Build());

            List <AuditTableModel> audits = await _auditDAO.Get(selectSpecification);

            DataTableResult <AuditTableModel> dataTableResult = new DataTableResult <AuditTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: auditsCount,
                recordsFiltered: auditsCount,
                data: audits);

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

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

            ISelectSpecificationBuilder <GroupUserEntity, GroupUserTableModel> specificationBuilder = SpecificationBuilder
                                                                                                      .Create <GroupUserEntity>()
                                                                                                      .Where(x => x.GroupId == groupId)
                                                                                                      .SearchByUsernameEmailId(request.Search)
                                                                                                      .OrderByDessending(x => x._CreatedDate)
                                                                                                      .Select(x => new GroupUserTableModel(
                                                                                                                  x.Id,
                                                                                                                  x.UserId,
                                                                                                                  x.User.UserName,
                                                                                                                  x.User.Email,
                                                                                                                  x.RoleId,
                                                                                                                  x.Role.Name));

            IBaseSpecification <GroupUserEntity, GroupUserTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <GroupUserEntity, GroupUserTableModel> dataSpecification  = specificationBuilder
                                                                                           .Paginate(request.Start, request.Length)
                                                                                           .Build();

            int count = await _groupUserDAO.Count(countSpecification);

            List <GroupUserTableModel> groupUsers = await _groupUserDAO.Get(dataSpecification);

            DataTableResult <GroupUserTableModel> dataTableResult = new DataTableResult <GroupUserTableModel>(
                draw: request.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: groupUsers);

            return(Result.Ok(dataTableResult));
        }
        public async Task <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.ToResultError()));
            }

            ISelectSpecificationBuilder <InviteEntity, GroupInviteTableModel> specificationBuilder = SpecificationBuilder
                                                                                                     .Create <InviteEntity>()
                                                                                                     .Where(x => x.GroupId == groupId)
                                                                                                     .SearchByEmail(dataTableRequest.Search)
                                                                                                     .OrderByDessending(x => x._CreatedDate)
                                                                                                     .Select(x => new GroupInviteTableModel(
                                                                                                                 x.Id,
                                                                                                                 x.Email,
                                                                                                                 x.GroupRole.Name,
                                                                                                                 x.Status.GetDescription(),
                                                                                                                 x.ExpiresAt.ToString("o")));

            IBaseSpecification <InviteEntity, GroupInviteTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <InviteEntity, GroupInviteTableModel> dataSpecification  = specificationBuilder
                                                                                          .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                          .Build();

            int count = await _inviteDAO.Count(countSpecification);

            var data = await _inviteDAO.Get(dataSpecification);


            DataTableResult <GroupInviteTableModel> dataTableResult = new DataTableResult <GroupInviteTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: data);

            return(Result.Ok(dataTableResult));
        }
Beispiel #6
0
        public async Task <Result <DataTableResult <GroupAttributeTableModel> > > Get(string groupId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(dataTableRequest)} model");
                return(Result.Fail <DataTableResult <GroupAttributeTableModel> >(validationResult.ToResultError()));
            }

            ISelectSpecificationBuilder <GroupAttributeEntity, GroupAttributeTableModel> specificationBuilder = SpecificationBuilder
                                                                                                                .Create <GroupAttributeEntity>()
                                                                                                                .Where(x => x.GroupId == groupId)
                                                                                                                .SearchByKey(dataTableRequest.Search)
                                                                                                                .OrderByDessending(x => x._CreatedDate)
                                                                                                                .Select(x => new GroupAttributeTableModel(
                                                                                                                            x.Id,
                                                                                                                            x.Key,
                                                                                                                            x.Value));

            IBaseSpecification <GroupAttributeEntity, GroupAttributeTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <GroupAttributeEntity, GroupAttributeTableModel> dataSpecification  = specificationBuilder
                                                                                                     .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                                     .Build();

            int count = await _groupAttributeDAO.Count(countSpecification);

            List <GroupAttributeTableModel> data = await _groupAttributeDAO.Get(countSpecification);

            DataTableResult <GroupAttributeTableModel> dataTableResult = new DataTableResult <GroupAttributeTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: data);

            return(Result.Ok(dataTableResult));
        }
Beispiel #7
0
        public Task <int> Count <TData>(IBaseSpecification <GroupUserEntity, TData> specification)
        {
            specification = ApplayGroupUserFilter(specification);

            return(_groupUserDAO.Count(specification));
        }