public IHttpActionResult Post(AddAuthorBindingModel model)
 {
     Author author = new Author { FirstName = model.FirstName, LastName = model.LastName};
     _context.Authors.Add(author);
     _context.SaveChanges();
     return this.Ok(author);
 }
        public void AddAuthor(AddAuthorBindingModel bindingModel)
        {
            var newAuthor = Mapper.Map <AddAuthorBindingModel, Author>(bindingModel);

            this.Context.Authors.Add(newAuthor);
            this.Context.SaveChanges();
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] AddAuthorBindingModel model)
        {
            // Filter added!!
            //if (!ModelState.IsValid)
            //{
            //    return this.BadRequest(ModelState);
            //}

            var author = this.mapper.Map <Author>(model);
            var id     = await this.authorsService.AddAsync(author);

            return(this.Ok(id));
        }
        public IHttpActionResult PostAuthor(AddAuthorBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            Author newAuthor = new Author {
                FirstName = model.FirstName, LastName = model.LastName
            };

            this.context.Authors.Add(newAuthor);
            this.context.SaveChanges();
            return(this.Ok(newAuthor));
        }
Пример #5
0
        public IHttpActionResult PostAuthor(AddAuthorBindingModel authorBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var author = new Author(authorBindingModel.FirstName, authorBindingModel.LastName);

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

            var authorViewModel = new AuthorViewModel(author);

            return(CreatedAtRoute("DefaultApi", new { id = authorViewModel.Id }, authorViewModel));
        }
Пример #6
0
        public IHttpActionResult PostAuthor(AddAuthorBindingModel authorModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            return(this.Ok("Author created"));
        }
        public ActionResult AddAuthor([Bind(Include = "Id,FullName,Bio")] AddAuthorBindingModel bindingModel)
        {
            if (ModelState.IsValid)
            {
                if (this.authorService.IsAuthorExists(bindingModel.FullName))
                {
                    this.TempData["Error"] = $"Author with name {bindingModel.FullName} already exists";
                    return(View(bindingModel));
                }

                this.authorService.AddAuthor(bindingModel);
                AuthorViewModel newAuthor = this.authorService.GetCurrentAuthor(bindingModel.FullName);

                this.TempData["Success"] = $"Author is created successfully";
                return(RedirectToAction("Details", "Authors", new { id = newAuthor.Id }));
            }

            return(View(bindingModel));
        }
Пример #8
0
        public IHttpActionResult AddAuthor(AddAuthorBindingModel model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model is empty");
            }
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            var author = new Author()
            {
                FirstName = model.FirstName ?? null,
                LastName  = model.LastName
            };

            db.Authors.Add(author);
            db.SaveChanges();
            return(this.CreatedAtRoute("DefaultApi", new { id = author.Id }, author));
        }
Пример #9
0
 public IHttpActionResult Post(AddAuthorBindingModel model)
 {
     _context.Authors.Add(author);
     _context.SaveChanges();
     return(this.Ok(author));
 }