public async Task <Result <GendersResponse> > Handle(GetGenderByIdQuery query, CancellationToken cancellationToken) { var item = await _repository.GetByIdAsync(query.Id); var mappedCategory = _mapper.Map <GendersResponse>(item); return(Result <GendersResponse> .Success(mappedCategory)); }
public async Task <Result <int> > Handle(DeleteGenderCommand command, CancellationToken cancellationToken) { var category = await _categoryRepository.GetByIdAsync(command.Id); await _categoryRepository.DeleteAsync(category); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(category.Id)); }
public async Task <Result <int> > Handle(UpdateGenderCommand command, CancellationToken cancellationToken) { var category = await _categoryRepository.GetByIdAsync(command.Id); if (category == null) { return(Result <int> .Fail($"Gender Not Found.")); } else { category.Name = command.Name ?? category.Name; category.Code = command.Code ?? category.Code; category.Description = command.Description ?? category.Description; await _categoryRepository.UpdateAsync(category); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(category.Id)); } }