예제 #1
0
        public FoodCategoryDto ToDto(FoodCategory foodCategory)
        {
            FoodCategoryDto foodCategoryDto = new FoodCategoryDto();

            //foodCategoryDto.drink = foodCategory.drink;
            //foodCategoryDto.food = foodCategory.food;
            return(foodCategoryDto);
        }
예제 #2
0
        public async Task <BaseDtoResponse <FoodCategoryDto> > GetById(Guid id)
        {
            FoodCategory category = await _foodCategoryRepository.GetById(id);

            if (category == null)
            {
                return(new BaseDtoResponse <FoodCategoryDto>("Category Not Found"));
            }
            FoodCategoryDto result = _mapper.Map <FoodCategory, FoodCategoryDto>(category);

            return(new BaseDtoResponse <FoodCategoryDto>(result));
        }
예제 #3
0
        public async Task <BaseDtoResponse <FoodCategoryDto> > Add(FoodCategoryCreateRequest request)
        {
            try
            {
                FoodCategory model    = _mapper.Map <FoodCategoryCreateRequest, FoodCategory>(request);
                FoodCategory category = await _foodCategoryRepository.Add(model);

                if (category != null)
                {
                    FoodCategoryDto result = _mapper.Map <FoodCategory, FoodCategoryDto>(category);
                    return(new BaseDtoResponse <FoodCategoryDto>(result));
                }
                else
                {
                    return(new BaseDtoResponse <FoodCategoryDto>("Unable to create a new category, try again"));
                }
            }
            catch (Exception ex)
            {
                return(new BaseDtoResponse <FoodCategoryDto>($"An error occurred when saving the category: {ex.Message}"));
            }
        }
예제 #4
0
        public async Task <BaseDtoResponse <FoodCategoryDto> > Delete(Guid id)
        {
            try
            {
                FoodCategory category = await _foodCategoryRepository.GetById(id);

                if (category != null)
                {
                    await _foodCategoryRepository.Delete(category);

                    FoodCategoryDto result = _mapper.Map <FoodCategory, FoodCategoryDto>(category);
                    return(new BaseDtoResponse <FoodCategoryDto>(result));
                }
                else
                {
                    return(new BaseDtoResponse <FoodCategoryDto>("Unable to delete: Category Not found"));
                }
            }
            catch (Exception ex)
            {
                return(new BaseDtoResponse <FoodCategoryDto>($"An error occurred when deleting the category: {ex.Message}"));
            }
        }
예제 #5
0
        public FoodCategory ToEntity(FoodCategoryDto foodCategoryDto)
        {
            FoodCategory foodCategory = new FoodCategory();

            return(foodCategory);
        }