public async Task <ActionResult <IdsDto> > Create ([FromBody] CreatedCategoryCommand createCategoryCommand) { var result = await _mediator.Send(createCategoryCommand); if (result.Status == ResponseStatus.BussinesLogicError) { return(Forbid(result.Message)); } if (result.Status == ResponseStatus.NotFoundInDataBase) { return(NotFound(result.Message)); } if (result.Status == ResponseStatus.ValidationError) { return(BadRequest(result.Message)); } if (result.Status == ResponseStatus.BadQuery) { return(BadRequest(result.Message)); } if (!result.Success) { return(MethodFailure(result.Message)); } return(Ok(result.CategoryIds)); }
public async Task <ActionResult <CreatedCategoryCommandResponse> > Create ([FromBody] CreatedCategoryCommand createCategoryCommand) { var response = await _mediator.Send(createCategoryCommand); return(Ok(response)); }
public async Task <ResponseFromApi <int> > CreateCategory(CategoryBlazorVM categoryViewModel) { try { ResponseFromApi <int> apiResponse = new ResponseFromApi <int>(); CreatedCategoryCommand createCategoryCommand = _mapper.Map <CreatedCategoryCommand>(categoryViewModel); var createCategoryCommandResponse = await _client.AddCategoryAsync(createCategoryCommand); if (createCategoryCommandResponse.Success) { apiResponse.Data = createCategoryCommandResponse.CategoryId.Value; apiResponse.Success = true; } else { apiResponse.Data = -1; foreach (var error in createCategoryCommandResponse.ValidationErrors) { apiResponse.ValidationErrors += error + Environment.NewLine; } } return(apiResponse); } catch (ApiException ex) { return(ex.ConvertApiExceptions()); } }