Beispiel #1
0
        public async Task <IActionResult> Index()
        {
            using (var context = new EfDbWebContext())
            {
                var model = await context.Authors.AsNoTracking().ToListAsync();

                return(View(model));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Title, AuthorId")] Book book)
        {
            using (var context = new EfDbWebContext())
            {
                context.Books.Add(book);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("FirstName, LastName")] Author author)
        {
            using (var context = new EfDbWebContext())
            {
                context.Add(author);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Create()
        {
            using (var context = new EfDbWebContext())
            {
                var authors = await context.Authors.Select(a => new SelectListItem {
                    Value = a.AuthorId.ToString(),
                    Text  = $"{a.FirstName} {a.LastName}"
                }).ToListAsync();

                ViewBag.Authors = authors;
            }
            return(View());
        }