Пример #1
0
        public IHttpActionResult PostAuthor([FromBody] AuthorBindingMethod model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var author = new Author()
            {
                FirstName = model.FirstName,
                LastName  = model.LastName
            };

            var context = new BookShopContext();

            context.Authors.Add(author);
            context.SaveChanges();

            var authorView = new AuthorViewModel.AuthorInfoViewModel()
            {
                FirstName = author.FirstName,
                LastName  = author.LastName
            };

            return(this.Ok(authorView));
        }
Пример #2
0
        public IHttpActionResult PostAuthor([FromBody] AuthorBindingMethod model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var author = new Author()
            {
                FirstName = model.FirstName,
                LastName = model.LastName
            };

            var context = new BookShopContext();
            context.Authors.Add(author);
            context.SaveChanges();

            var authorView = new AuthorViewModel.AuthorInfoViewModel()
            {
                FirstName = author.FirstName,
                LastName = author.LastName
            };
            return this.Ok(authorView);
        }