示例#1
0
        public IActionResult GetCuisinesV2(ResourceParameter parameters)
        {
            var response = new ListModelResponse <MainMenuDto>() as IListModelResponse <MainMenuDto>;

            //throw new InvalidOperationException("This is an unhandled exception");
            //throw new ECafeException("error occured");

            if (!_propertyMappingService.ValidMappingExistsFor <MainMenuDto, MainMenu>(parameters.OrderBy))
            {
                logger.LogError($"Invalid mapping requested in {this.GetType().Name} Method Name");
                return(response.ToErrorResponse("Invalid mapping requested", HttpStatusCode.BadRequest));
            }

            if (!typeHelperService.TypeHasProperties <MainMenuDto>(parameters.Fields))
            {
                return(response.ToErrorResponse("Invalid properties name requested", HttpStatusCode.BadRequest));
            }

            var results = _mainMenuGetService.GetAll(parameters);

            //***Create pagination header
            var paginationMetadata = ResourceUri <MainMenu> .CreatePaginationHeader(parameters, results, urlHelper, "GetCuisines");

            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

            //***Mapping Entity to Dto
            var medicineTypes = AutoMapper.Mapper.Map <IEnumerable <MainMenuDto> >(results);

            response.ShapeModel = medicineTypes.ShapeData(parameters.Fields);
            response.Model      = new List <MainMenuDto>();
            response.Message    = $"Total of records: {response.ShapeModel.Count()}";
            response.PageSize   = parameters.PageSize;
            response.PageNumber = parameters.PageNumber;
            return(response.ToHttpResponse());
        }