Пример #1
0
        public IActionResult Update(int id)
        {
            var idUser = Int32.Parse(User.FindFirst("IdUsuario")?.Value);
            var user   = _authorService.FindUserById(idUser);

            if (user.Admin != true)
            {
                return(RedirectToAction("AccessDenied", "Users"));
            }



            if (id == 0)
            {
                return(NotFound());
            }
            var obj = _authorService.FindAuthorById(id);

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

            List <Team>           teams     = _teamService.FindAll();
            UpdateAuthorViewModel viewModel = new UpdateAuthorViewModel {
                Author = obj, Teams = teams
            };

            return(View(viewModel));
        }
Пример #2
0
        public async Task Update(UpdateAuthorViewModel item)
        {
            var updatedItem = Mapper.Map <UpdateAuthorViewModel, Author>(item);
            await _authorRepository.Update(updatedItem);

            var books = Mapper.Map <ICollection <BookUpdateAuthorViewModelItem>, List <Book> >(item.Books);
            await _authorInBookRepository.UpdateBooksByAuthorId(item.Id, books);
        }
Пример #3
0
        public IActionResult Update(int id, UpdateAuthorViewModel obj)
        {
            if (id != obj.Author.Id)
            {
                return(BadRequest());
            }



            _authorService.UpdateAuthor(obj.Author);
            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        public async Task <IActionResult> Update([FromBody] UpdateAuthorViewModel itemVM)
        {
            if (itemVM == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _service.Update(itemVM);

            return(Ok(itemVM));
        }
Пример #5
0
        public void Update(UpdateAuthorViewModel authorViewModel)
        {
            if (_authorRepository.Get(authorViewModel.Id) == null)
            {
                throw new BusinessLogicException("Author not found");
            }

            var author = new Author()
            {
                Id   = authorViewModel.Id,
                Name = authorViewModel.Name
            };

            _authorRepository.Update(author);
        }
Пример #6
0
 public IActionResult Update([FromBody] UpdateAuthorViewModel author)
 {
     try
     {
         _authorService.Update(author);
         return(Ok(author));
     }
     catch (BusinessLogicException exception)
     {
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         _logger.LogInformation(exception.Message);
         return(StatusCode((int)HttpStatusCode.InternalServerError));
     }
 }
        public void UpdateAuthor(UpdateAuthorViewModel updateAuthorViewModel)
        {
            Author author = Mapper.Map <UpdateAuthorViewModel, Author>(updateAuthorViewModel);

            _authorRepository.Update(author);
        }
 public void UpdateAuthor(UpdateAuthorViewModel updateAuthorViewModel)
 {
     _authorService.UpdateAuthor(updateAuthorViewModel);
 }