Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID, Name, CourseID")] Student student)
        {
            await _context.Students.AddAsync(student);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID, Name, Description")] Course course)
        {
            await _context.AddAsync(course);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,CourseID,Description")] Course course)
        {
            if (ModelState.IsValid)
            {
                await _context.Courses.AddAsync(course);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(course));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Age,CourseID")] Student student)
        {
            if (ModelState.IsValid)
            {
                await _context.Students.AddAsync(student);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(StudentCreateViewModel.CreateStudent(_context)));
        }
Ejemplo n.º 5
0
        public async void DbCanSaveTest()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                // Arrange
                Course course = new Course();
                course.Name        = "DotNet";
                course.Description = "Embrace the flood";

                Student student = new Student();
                student.Name     = "Someone";
                student.CourseID = 1;

                // Act
                await context.Courses.AddAsync(course);

                await context.Students.AddAsync(student);

                await context.SaveChangesAsync();

                var results  = context.Courses.Where(a => a.Name == "DotNet");
                var results2 = context.Students.Where(a => a.Name == "Someone");
                // Assert
                Assert.Equal(1, results.Count());
                Assert.Equal(1, results2.Count());
            }
        }
        public async void CourseControllerCanCreate()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                Course course = new Course();
                course.CourseID    = "cs101";
                course.Description = "Basic computer science class";
                //Act
                await context.Courses.AddAsync(course);

                await context.SaveChangesAsync();

                var results = context.Courses.Where(c => c.CourseID == "cs101");
                //Assert
                Assert.Equal(1, results.Count());
            }
        }
        public async void StudentsControllerCanCreate()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                //Arrange
                Student student = new Student();
                student.Name     = "Bob";
                student.Age      = 24;
                student.CourseID = "cs101";
                //Act
                await context.Students.AddAsync(student);

                await context.SaveChangesAsync();

                var results = context.Students.Where(s => s.Name == "Bob");
                //Assert
                Assert.Equal(1, results.Count());
            }
        }