Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
        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));
        }