コード例 #1
0
 public IActionResult Create(Author author)
 {
     if (ModelState.IsValid)
     {
         _context.Author.Add(author);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(author);
 }
コード例 #2
0
        private Author GetOrCreateAuthor(string authorName)
        {
            var author = this.bookStoreDbContext.Authors
                             .FirstOrDefault(a => a.Name == authorName);

            if (author == null)
            {
                author = new Author()
                {
                    Name = authorName
                };
            }

            return author;
        }