Пример #1
0
        public async Task <Response <GetCategoryViewModel> > GetById(int id)
        {
            var category = await _categoryRepository.GetByIdAsync(id);

            var result = _mapper.Map <GetCategoryViewModel>(category);

            return(new Response <GetCategoryViewModel>(result));
        }
Пример #2
0
        public async Task <Response <GetCategoryByIdDto> > Handle(GetCategoryByIdQuery request, CancellationToken cancellationToken)
        {
            var rq       = _mapper.Map <GetCategoryByIdRequest>(request);
            var category = await _CategoryRepository.GetByIdAsync(rq.Id);

            var response = _mapper.Map <GetCategoryByIdDto>(category);

            return(new Response <GetCategoryByIdDto>(response));
        }
        public async Task <Response <DeleteCategoryDto> > Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
        {
            var category = await _CategoryRespository.GetByIdAsync(request.Id);

            if (category == null)
            {
                throw new ApiException($"Category Not Found.");
            }
            await _CategoryRespository.RemoveAsync(category);

            var response = _mapper.Map <DeleteCategoryDto>(category);

            return(new Response <DeleteCategoryDto>(_mapper.Map <DeleteCategoryDto>(category), "Category remove successful"));
        }
Пример #4
0
        public async Task <Response <UpdateCategoryDto> > Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
        {
            var command  = _mapper.Map <UpdateCategoryRequest>(request);
            var category = await _CategoryRepository.GetByIdAsync(command.Id);

            if (category == null)
            {
                throw new ApiException($"Category Not Found.");
            }
            else
            {
                category.Name        = command.Name;
                category.Description = command.Description;
                await _CategoryRepository.UpdateAsync(category);

                return(new Response <UpdateCategoryDto>(_mapper.Map <UpdateCategoryDto>(category), "Category Update Successufull"));
            }
        }