public async Task <IActionResult> Get([FromQuery] DataTableRequest dataTableRequest, [FromQuery] AuditTableRequest auditTableRequest) { Result <DataTableResult <AuditAdminTableModel> > result = await _auditDataService.Get(dataTableRequest, auditTableRequest); return(result.ToApiResult()); }
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 <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)); }
public async Task <IActionResult> Get([FromQuery] DataTableRequest dataTableRequest, [FromQuery] AuditTableRequest auditTableRequest) { if (!_identityUIEndpoints.ShowAuditToUser) { return(NotFound()); } Result <DataTableResult <AuditTableModel> > result = await _auditDataService.Get(dataTableRequest, auditTableRequest); return(result.ToApiResult()); }