public virtual IActionResult CreateBook([FromRoute][Required] Guid?authorId, [FromBody] BookForCreationWithAmountOfPages body) { //TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(201, default(Book)); //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(400, default(ProblemDetails)); //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(404, default(ProblemDetails)); //TODO: Uncomment the next line to return response 406 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(406, default(ProblemDetails)); //TODO: Uncomment the next line to return response 422 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(422, default(ValidationProblemDetails)); //TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(500, default(Void)); string exampleJson = null; var example = exampleJson != null ? JsonConvert.DeserializeObject <Book>(exampleJson) : default(Book); //TODO: Change the data returned return(new ObjectResult(example)); }
public async Task <ActionResult <Book> > CreateBookWithAmountOfPages( Guid authorId, [FromBody] BookForCreationWithAmountOfPages bookForCreation) { if (!await _authorRepository.AuthorExistsAsync(authorId)) { return(NotFound()); } var bookToAdd = _mapper.Map <Entities.Book>(bookForCreation); _bookRepository.AddBook(bookToAdd); await _bookRepository.SaveChangesAsync(); return(CreatedAtRoute( "GetBook", new { authorId, bookId = bookToAdd.Id }, _mapper.Map <Book>(bookToAdd))); }
/// <summary> /// Create a book for a specific author /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorId">The id of the book author</param> /// <param name="body"> (optional)</param> /// <returns>Task of Book</returns> public async System.Threading.Tasks.Task <Book> CreateBookAsync(Guid?authorId, BookForCreationWithAmountOfPages body = null) { ApiResponse <Book> localVarResponse = await CreateBookAsyncWithHttpInfo(authorId, body); return(localVarResponse.Data); }
/// <summary> /// Create a book for a specific author /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorId">The id of the book author</param> /// <param name="body"> (optional)</param> /// <returns>Task of ApiResponse (Book)</returns> public async System.Threading.Tasks.Task <ApiResponse <Book> > CreateBookAsyncWithHttpInfo(Guid?authorId, BookForCreationWithAmountOfPages body = null) { // verify the required parameter 'authorId' is set if (authorId == null) { throw new ApiException(400, "Missing required parameter 'authorId' when calling BooksApi->CreateBook"); } var localVarPath = "/api/v1/authors/{authorId}/books"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "application/vnd.marvin.bookforcreation+json", "application/vnd.marvin.bookforcreationwithamountofpages+json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "application/xml" }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (authorId != null) { localVarPathParams.Add("authorId", this.Configuration.ApiClient.ParameterToString(authorId)); // path parameter } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("CreateBook", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Book>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (Book)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Book)))); }
/// <summary> /// Create a book for a specific author /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorId">The id of the book author</param> /// <param name="body"> (optional)</param> /// <returns>Book</returns> public Book CreateBook(Guid?authorId, BookForCreationWithAmountOfPages body = null) { ApiResponse <Book> localVarResponse = CreateBookWithHttpInfo(authorId, body); return(localVarResponse.Data); }