Пример #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validator = new PagingValidator();
            var result    = validator.Validate(this);

            return(result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName })));
        }
Пример #2
0
        public async Task <ActionResult> GetCustomerCollection([FromQuery] GetCustomerRequest request)
        {
            LogStart();
            try
            {
                var errorInfo = new ErrorInfo();

                // Paging
                errorInfo = PagingValidator.Validate(request.PageIndex, request.PageSize, _appSetting.MaximumPageSize, out int pageIndex, out int pageSize);
                if (errorInfo.ErrorCode != ErrorTypes.OK)
                {
                    throw new BadInputException(errorInfo);
                }

                // Sort Field
                errorInfo = SortFieldValidator.Validate <CustomerModel>(request.SortField, out string sortField);
                if (errorInfo.ErrorCode != ErrorTypes.OK)
                {
                    throw new BadInputException(errorInfo);
                }

                var result = await _customerRepository.GetCustomersListAsync();

                var count = result.Count();

                var resultDto = new PagingDto <CustomerDto>
                {
                    Collection   = _mapper.Map <List <CustomerDto> >(result),
                    PageIndex    = pageIndex,
                    PageSize     = pageSize,
                    TotalRecords = count,
                    TotalPages   = (int)((count - 1) / pageSize + 1)
                };

                LogEnd();
                return(Ok(resultDto));
            }
            catch (Exception ex)
            {
                LogError(ex);
                throw ex;
            }
        }
Пример #3
0
 public PagingValidatorTest()
 {
     validator = new PagingValidator();
 }