Ejemplo n.º 1
0
        public async Task<IActionResult> Create([Bind("Name, ID, CourseId, Passing, HoursOfSleep")]Student student)
        {
            student.Course = await _context.Course.Where(c => c.ID == student.CourseId).SingleAsync();

            await _context.Student.AddAsync(student);
            await _context.SaveChangesAsync();
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID, ClassName, StartingDate, EndDate, Instructor")] Course course)
        {
            await _context.Course.AddAsync(course);

            await _context.SaveChangesAsync();

            int id = course.ID;

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Age")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("ID,CourseCode,Technology,Price")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CourseID,StudentID")] Enrollments enrollments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "ID", "ID", enrollments.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "ID", enrollments.StudentID);
            return(View(enrollments));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("ID,Name,MaxStudents")] Course course)
        {
            if (ModelState.IsValid)
            {
                await _context.Courses.AddAsync(course);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public async Task <IActionResult> Create([Bind("ID, Name, Course, CourseID")] Student student)
        {
            await _context.Students.AddAsync(student);

            await _context.SaveChangesAsync();

            int id = student.ID;

            return(View());
        }
Ejemplo n.º 8
0
        public async void DatabaseCanSaveAsync()
        {
            DbContextOptions <EnrollmentDbContext> options =
                new DbContextOptionsBuilder <EnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (EnrollmentDbContext context = new EnrollmentDbContext(options))
            {
                Course course = new Course();
                course.ClassName    = ClassName.Python;
                course.Instructor   = "Miss Snake";
                course.StartingDate = new DateTime(2012, 12, 12);
                course.EndDate      = new DateTime(2012, 12, 25);

                await context.Course.AddAsync(course);

                await context.SaveChangesAsync();

                var results = context.Course.Where(a => a.Instructor == "Miss Snake");

                Assert.Equal(1, results.Count());
            }
        }