Пример #1
0
        private void SetupDatabase()
        {
            Options = new DbContextOptionsBuilder <BlogPostContext>()
                      .UseInMemoryDatabase(databaseName: "StudentContextOptions")
                      .Options;

            using var dbContext = new BlogPostContext(Options);
            var itCourse = new Course
            {
                Name = "IT Programming"
            };

            var math = new Course
            {
                Name = "Math"
            };

            var student1 = new Student
            {
                Name    = "John Doe",
                Courses = new List <StudentCourse>
                {
                    new StudentCourse {
                        Course = itCourse
                    },
                    new StudentCourse {
                        Course = math
                    }
                }
            };

            var student2 = new Student
            {
                Name    = "Martin B",
                Courses = new List <StudentCourse>
                {
                    new StudentCourse {
                        Course = itCourse
                    },
                    new StudentCourse {
                        Course = math
                    }
                }
            };

            dbContext.Add(student1);
            dbContext.Add(student2);

            dbContext.SaveChanges();

            allStudents = new List <Student> {
                student1, student2
            };
            ExpectedStudents = Mapper.Map <IEnumerable <StudentResponse> >(allStudents);
        }
Пример #2
0
        //public async Task<IActionResult> Create([Bind("BlogId,Name,Url,Detail_Author,Detail_ISBN")] Blog blog)
        public async Task <IActionResult> Create([Bind("BlogId,Name,Url,Detail")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }