Beispiel #1
0
        public async Task <Page <BudgetDto> > SearchBudgetsAsync(SearchBudgetsRequest request, PaginationRequest paginationRequest, CancellationToken cancellationToken)
        {
            var caller  = CallerExtensions.LogCaller();
            var pageDto = await SearchAsync((pageOptions) => _budgetService.SearchBudgets(request.Filter, request.Sort, pageOptions), paginationRequest, caller.Method, cancellationToken);

            return(pageDto);
        }
        public async Task <CommandResult <Page <BudgetDto> > > SearchBudgetsAsync(SearchBudgetsRequest request, CancellationToken cancellationToken)
        {
            var parameters = new { request, cancellationToken };

            try
            {
                if (request == null)
                {
                    return(ExceptionExtensions.GetBadResponse <Page <BudgetDto> >(parameters));
                }

                //request.Filter = RequestExtensions.GetFilterRequest(Request.Url.Query);
                //parameters = new { request, cancellationToken };
            }

            catch (Exception e)
            {
                return(e.GetBadResponse <Page <BudgetDto> >(parameters));
            }

            var validator        = new SearchBudgetsRequestValidator();
            var validationResult = await validator.ValidateAsync(request, cancellationToken);

            if (!validationResult.IsValid)
            {
                return(validationResult.GetBadResponse <Page <BudgetDto> >(parameters));
            }

            try
            {
                var paginationRequest = new PaginationRequest()
                {
                    Cursor = null,
                    Limit  = DefaultPageLimit
                };
                var dtoPage = await _moduleImpl.SearchBudgetsAsync(request, paginationRequest, cancellationToken);

                if (dtoPage == null)
                {
                    return(CommandResult <Page <BudgetDto> > .NotFound());
                }

                return(CommandResult <Page <BudgetDto> > .Ok(dtoPage));
            }

            catch (UnsupportedFilterPropertyException unsupportedFilterProperty)
            {
                return(unsupportedFilterProperty.GetBadResponse <Page <BudgetDto> >(parameters));
            }

            catch (EntityPropertyNameNotDefinedException entityPropertyNameNotDefined)
            {
                return(entityPropertyNameNotDefined.GetBadResponse <Page <BudgetDto> >(parameters));
            }

            catch (Exception e)
            {
                return(e.GetInternalServerErrorResponse <Page <BudgetDto> >(parameters));
            }
        }