Beispiel #1
0
        public async Task <BaseDtoListResponse <FoodItemDto> > GetItemsByCategory(Guid CategoryId)
        {
            try
            {
                FoodCategory category = await _foodCategoryRepository.GetById(CategoryId);

                if (category == null)
                {
                    return(new BaseDtoListResponse <FoodItemDto>("There is no category with requested Id"));
                }
                IList <FoodItem> items = await _foodItemRepository.List(new ItemsByCategorySpecification(CategoryId));

                if (items != null)
                {
                    IList <FoodItemDto> result = _mapper.Map <IList <FoodItem>, IList <FoodItemDto> >(items).ToList();
                    return(new BaseDtoListResponse <FoodItemDto>(result));
                }
                else
                {
                    return(new BaseDtoListResponse <FoodItemDto>(new List <FoodItemDto>()));
                }
            }
            catch (Exception ex)
            {
                return(new BaseDtoListResponse <FoodItemDto>($"An error occurred when deleting the item: {ex.Message}"));
            }
        }