示例#1
0
        public ActionResult Create(AuthorPostModel model)
        {
            var author = _mapper.Map <AuthorModel>(model);

            _authorService.Create(author);

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult <string> > PostAuthor([FromBody] AuthorPostModel authorPostModel)
        {
            Author author = new Author(authorPostModel.Author);

            // Добавляем в базу данных переданного автора.
            _context.Authors.Add(author);

            // Сохраняем изменения базы данных.
            await _context.SaveChangesAsync();

            return(JsonConvert.SerializeObject(author));
        } // PostAuthor.
        public IActionResult Post([FromBody] AuthorPostModel postModel)
        {
            if (postModel == null)
            {
                return(BadRequest());
            }

            _libraryRepository.AddAuthor(postModel.GetEntity());

            _libraryRepository.Save();

            return(CreatedAtRoute("GetAuthor", new { id = postModel.Id }, new AuthorGetModel(postModel.GetEntity())));
        }
        public async Task <ActionResult <Author> > PostAuthor(AuthorPostModel authorPost)
        {
            Author author = _mapper.Map <Author>(authorPost);

            _context.Author.Add(author);
            bool IsSaveAuthor = await _authorServices.AddNewBook(author);

            if (IsSaveAuthor)
            {
                return(Ok(new { data = author, success = true }));
            }
            else
            {
                return(Ok(new { error_message = "Co loi khi luu tac gia" }));
            }
        }
示例#5
0
        public IActionResult Post([Required][FromBody] AuthorPostModel model)
        {
            if (ModelState.IsValid)
            {
                AuthorDTO newAuthor = new AuthorDTO
                {
                    Name        = model.Name.Trim(),
                    Description = model.Description,
                    Surname     = model.Surname.Trim(),
                    Image       = model.Image
                };

                _dataWriter.Add(newAuthor);
            }

            return(Ok());
        }
        public async Task <IActionResult> PutAuthor(AuthorPostModel authorPostModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { error_message = "Loi cu phap" }));
            }
            Author author = await _authorServices.FindAuthorAsync(authorPostModel.Id);

            if (author is null)
            {
                return(Ok(new { error_message = "Khong tim thay tac gia" }));
            }
            bool IsUpdateAuthor = await _authorServices.UpdateAuthorAsync(author, authorPostModel);

            if (IsUpdateAuthor)
            {
                return(Ok(new { data = author, success = true }));
            }
            else
            {
                return(Ok(new { error_message = "Khong co gi thay doi" }));
            }
        }
 internal async Task <bool> UpdateAuthorAsync(Author author, AuthorPostModel authorPostModel)
 {
     author.AuthorName = authorPostModel.AuthorName;
     return(await _bookstoreContext.SaveChangesAsync() != 0);
 }