コード例 #1
0
 public void Edit(BookViewModel bookViewModel)
 {
     if (repo.IsAdmin())
     {
         repo.Update(Mapper.Map <Book>(bookViewModel));
     }
     else
     {
         throw new AccessViolationException();
     }
 }
コード例 #2
0
        public async Task<ActionResult> Edit(Guid id, IFormCollection form)
        {
            try
            {
                await _booksRepo.Update(new Book()
                {
                    Id = id,
                    Title = form["Title"],
                    Author = form["Author"],
                    ReleaseDate = Convert.ToDateTime(form["ReleaseDate"]),
                    Description = form["Description"]
                });

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }