示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Students).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentsExists(Students.StudentId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Students.Add(Students);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Students = await _context.Students.FindAsync(id);

            if (Students != null)
            {
                _context.Students.Remove(Students);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Courses = await _context.Courses.FindAsync(id);

            if (Courses != null)
            {
                _context.Courses.Remove(Courses);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#5
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            int    StudentId = Enrollment.StudentId;
            string courseNum = Enrollment.CourseNum;

            if (id == null)
            {
                return(NotFound());
            }

            Enrollment = await _context.Enrollment.FindAsync(Enrollment.CourseNum, Enrollment.StudentId);

            if (Enrollment != null)
            {
                _context.Enrollment.Remove(Enrollment);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Enrollm"));
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync()
        {
            IList <CoursesOffered> CoursesOfferedList = await _context.CoursesOffered.OrderBy(c => c.CourseNum).ToListAsync();

            string           selCourse = SelectedCourse;
            IList <Students> StuList   = await _context.Students.OrderBy(s => s.StudentId).ToListAsync();

            int selStudent = SelectedStudent;


            IList <Prerequisites> PrereqList = null;

            if (CoursesOfferedList.Count > 0)
            {
                PrereqList = await _context.Prerequisites
                             //.Include(p => p.PrereqCnum)
                             .Include(p => p.PrereqCnumNavigation)
                             .Where(p => p.CourseNum == selCourse)
                             .ToListAsync();
            }
            IList <CoursesTaken> coursesTakenList = null;

            if (StuList.Count > 0)
            {
                coursesTakenList = await _context.CoursesTaken
                                   .Include(s => s.Student)
                                   .Where(s => s.StudentId == selStudent)
                                   .ToListAsync();
            }
            int prereqcount = 0;

            foreach (var item in PrereqList)
            {
                foreach (var courseTaken in coursesTakenList)
                {
                    if (courseTaken.CourseNumNavigation == item.PrereqCnumNavigation)
                    {
                        prereqcount++;
                    }
                }
            }

            if (prereqcount == PrereqList.Count)
            {
                Enrollment.CourseNum = selCourse;
                Enrollment.StudentId = selStudent;
                _context.Enrollment.Add(Enrollment);
                await _context.SaveChangesAsync();

                ViewData["msg"] = "";
                return(RedirectToPage("./Enrollm"));
            }
            else
            {
                ViewData["msg"] = "Student could not be registered due to Prerequisite requirement fail";
                string firstCourse = "";
                if (CoursesOfferedList.Count > 0)
                {
                    firstCourse = CoursesOfferedList[0].CourseNum;
                }
                int firstStudent = 0;
                if (StuList.Count > 0)
                {
                    firstStudent = StuList[0].StudentId;
                }
                SelectedCourse  = firstCourse;
                CSList          = new SelectList(CoursesOfferedList, "CourseNum", "CourseNum");
                SelectedStudent = firstStudent;
                StudentList     = new SelectList(StuList, "StudentId", "FirstName");
                return(Page());
            }

            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            //_context.Enrollment.Add(Enrollment);
            //await _context.SaveChangesAsync();

            //return RedirectToPage("./Enrollm");
        }