예제 #1
0
        public IActionResult UpdateAuthor([FromBody] AuthorForUpdate author, Guid id)
        {
            if (author == null)
            {
                return(BadRequest());
            }

            if (!_libraryRepository.AuthorExists(id))
            {
                return(NotFound());
            }


            _libraryRepository.UpdateAuthor(author, id);
            _libraryRepository.Save();

            var authorEntity = _libraryRepository.GetAuthor(id);

            var authorToReturn = authorEntity.Map();
            var links          = CreateLinksForAuthor(authorToReturn.Id, null);

            var linkedResourceToReturn = authorToReturn.ShapeData(null)
                                         as IDictionary <string, object>;

            linkedResourceToReturn.Add("links", links);

            return(CreatedAtRoute("GetAuthor",
                                  new { id = linkedResourceToReturn["Id"] },
                                  linkedResourceToReturn));
        }
        public void UpdateAuthor(AuthorForUpdate author, Guid authorId)
        {
            var authorEntity = GetAuthor(authorId);

            authorEntity.DateOfBirth = author.DateOfBirth ?? authorEntity.DateOfBirth;
            authorEntity.DateOfDeath = author.DateOfDeath ?? authorEntity.DateOfDeath;
            authorEntity.FirstName   = author.FirstName ?? authorEntity.FirstName;
            authorEntity.LastName    = author.LastName ?? authorEntity.LastName;
            authorEntity.Genre       = author.Genre ?? authorEntity.Genre;
        }
        public ActionResult <AuthorDto> UpdateAuthor(string authorId, AuthorForUpdate model)
        {
            var authorFromRepo = _courseLibraryRepository.GetAuthor(ObjectId.Parse(authorId));

            if (authorFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(model, authorFromRepo);

            _courseLibraryRepository.UpdateAuthor(ObjectId.Parse(authorId), authorFromRepo);

            return(Ok(_mapper.Map <AuthorDto>(authorFromRepo)));
        }
        public async Task <ActionResult <Author> > UpdateAuthor(Guid authorId, AuthorForUpdate authorForUpdate)
        {
            var authorFromRepo = await _authorsRepository.GetAuthorAsync(authorId);

            if (authorFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(authorForUpdate, authorFromRepo);

            //// update & save
            _authorsRepository.UpdateAuthor(authorFromRepo);
            await _authorsRepository.SaveChangesAsync();

            // return the author
            return(Ok(_mapper.Map <Author>(authorFromRepo)));
        }
        public async Task <ActionResult <Author> > UpdateAuthor(
            Guid authorId,
            AuthorForUpdate authorForUpdate)
        {
            var author = await _authorsRepository.GetAuthorAsync(authorId);

            if (author == null)
            {
                return(NotFound());
            }


            //// update & save
            await _authorsRepository.UpdateAuthor(author);

            await _authorsRepository.SaveChangesAsync();

            // return the author
            return(Ok(author));
        }
예제 #6
0
        /// <summary>
        /// Update an author
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="authorId">The id of the author to update</param>
        /// <param name="body"> (optional)</param>
        /// <returns>Task of ApiResponse (Author)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <Author> > UpdateAuthorAsyncWithHttpInfo(Guid?authorId, AuthorForUpdate body = null)
        {
            // verify the required parameter 'authorId' is set
            if (authorId == null)
            {
                throw new ApiException(400, "Missing required parameter 'authorId' when calling AuthorsApi->UpdateAuthor");
            }

            var    localVarPath         = "/api/v1/authors/{authorId}";
            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"
            };
            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.PUT, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("UpdateAuthor", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Author>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            (Author)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Author))));
        }
예제 #7
0
        /// <summary>
        /// Update an author
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="authorId">The id of the author to update</param>
        /// <param name="body"> (optional)</param>
        /// <returns>Task of Author</returns>
        public async System.Threading.Tasks.Task <Author> UpdateAuthorAsync(Guid?authorId, AuthorForUpdate body = null)
        {
            ApiResponse <Author> localVarResponse = await UpdateAuthorAsyncWithHttpInfo(authorId, body);

            return(localVarResponse.Data);
        }
예제 #8
0
        /// <summary>
        /// Update an author
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="authorId">The id of the author to update</param>
        /// <param name="body"> (optional)</param>
        /// <returns>Author</returns>
        public Author UpdateAuthor(Guid?authorId, AuthorForUpdate body = null)
        {
            ApiResponse <Author> localVarResponse = UpdateAuthorWithHttpInfo(authorId, body);

            return(localVarResponse.Data);
        }
예제 #9
0
        public virtual IActionResult UpdateAuthor([FromRoute][Required] Guid?authorId, [FromBody] AuthorForUpdate body)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(Author));

            //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 <Author>(exampleJson)
                        : default(Author);            //TODO: Change the data returned

            return(new ObjectResult(example));
        }