public IHttpActionResult Put(int id, [FromBody] AuthorUpdateModel author)
        {
            IHttpActionResult badRequest;

            if (!this.IsModelValid(ModelState, author, out badRequest))
            {
                return(badRequest);
            }

            try
            {
                var authorEntity = Database <Author> .Read(id);

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

                Mapper.Map(author, authorEntity);
                Database <Author> .Update(authorEntity);

                return(Ok());
            }
            catch (DataNotFoundException) {
                return(NotFound());
            }
        }
예제 #2
0
 public AuthorEntity MapAuthorUpdateModelToEntity(AuthorUpdateModel authorUpdateModel)
 {
     return(new AuthorEntity
     {
         Id = authorUpdateModel.Id,
         FirstName = authorUpdateModel.FirstName,
         LastName = authorUpdateModel.LastName,
         AboutAuthor = authorUpdateModel.AboutAuthor
     });
 }
        public IHttpActionResult Put(Guid id, [FromBody] AuthorUpdateModel authorModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var updatedAuthor = Mapper.Map <Author>(authorModel);
                updatedAuthor.Id = id;
                _authorRepository.Update(updatedAuthor);
                return(Ok());
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }
        }