Example #1
0
        public async Task <IActionResult> Search(CustomersSearchParametersModel parameters)
        {
            if (parameters.Limit <= Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var customersDto = await _customerApiService.SearchAsync(parameters.Query, parameters.Order, parameters.Page, parameters.Limit);

            var customersRootObject = new CustomersRootObject
            {
                Customers = customersDto
            };

            var json = JsonFieldsSerializer.Serialize(customersRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }