public Task <IActionResult> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken) { IActionResult response = new BadRequestResult(); try { var validatorResults = _updateValidator.Validate(request); if (!validatorResults.IsValid) { var errors = validatorResults.Errors.Select(f => f.ErrorMessage); var output = ApiResultHelper.GenerateErrorResponse(HttpStatusCode.UnprocessableEntity, errors); response = new UnprocessableEntityObjectResult(output); } else { var result = 0; var entity = _repository.GetById(request.CategoryId).Result; if (entity != null) { entity = _mapper.Map <Category>(request); result = _repository.Update(entity).Result; } response = new OkObjectResult(ApiResultHelper.GenerateResponse(HttpStatusCode.OK, result)); } } catch (Exception ex) { if (this._logger != null) { _logger.LogError(ex, "Exception"); } } return(Task.FromResult(response)); }