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

                return(View(model));
            }
        }
Exemple #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"));
            }
        }
        public async Task <IActionResult> Create([Bind("FirstName, LastName")] Author author)
        {
            using (var context = new EfDbWebContext())
            {
                context.Add(author);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
Exemple #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());
        }