public async Task <IActionResult> Edit(int id, [Bind("Id, FirstName,LastName")] AuthorViewModel authorViewModel) { if (id != authorViewModel.Id) { return(NotFound()); } if (ModelState.IsValid && _userManager.GetUserId(HttpContext.User) == null) { var author = authorViewModel.MapTo <Author>(); try { _context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(authorViewModel)); }
public async Task <IActionResult> Create([Bind("Id, FirstName,LastName")] AuthorViewModel authorViewModel) { if (ModelState.IsValid) { var author = authorViewModel.MapTo <Author>(); _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(authorViewModel)); }