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)); }
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); }
public IActionResult Update(int id, UpdateAuthorViewModel obj) { if (id != obj.Author.Id) { return(BadRequest()); } _authorService.UpdateAuthor(obj.Author); return(RedirectToAction(nameof(Index))); }
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)); }
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); }
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); }