コード例 #1
0
ファイル: StudentDbService.cs プロジェクト: s18727/cw10
        public void EnrollStudent(EnrollRequest student)
        {
            if (student.IndexNumber == null)
            {
                throw new Exception();
            }
            if (student.FirstName == null)
            {
                throw new Exception();
            }
            if (student.LastName == null)
            {
                throw new Exception();
            }
            if (student.BirthDate == null)
            {
                throw new Exception();
            }
            if (student.Studies == null)
            {
                throw new Exception();
            }

            var st = _context2.Studies.FirstOrDefault(st => st.Name.Equals(student.Studies));

            if (st == null)
            {
                throw new Exception();
            }

            var st2        = _context3.Enrolment.FirstOrDefault(stu => stu.IdStudy == st.IdStudy && stu.Semester == 1);
            var enrollment = new Enrollment();

            if (st2 == null)
            {
                enrollment.IdEnrollment = _context3.Enrolment.Last().IdEnrollment + 1;
                enrollment.Semester     = 1;
                enrollment.StartDate    = DateTime.Now;
                enrollment.IdStudy      = st.IdStudy;

                _context3.Add(enrollment);
                _context3.SaveChanges();
            }

            var st3 = _context.Student.FirstOrDefault(st => st.IndexNumber.Equals(student.IndexNumber));

            if (st3 != null)
            {
                throw new Exception();
            }
            else
            {
                var student2 = new Student();
                student2.IndexNumber  = student.IndexNumber;
                student2.FirstName    = student.FirstName;
                student2.LastName     = student.LastName;
                student2.BirthDate    = student.BirthDate;
                student2.IdEnrollment = enrollment.IdEnrollment;
            }
        }
コード例 #2
0
        public IActionResult Index(Enrollment enrollment)
        {
            _context.Enrollment.Add(enrollment);
            _context.SaveChanges();

            return(RedirectToAction("Details"));
        }
コード例 #3
0
        public IActionResult Index(Enrollment enrollment)
        {
            //add ind. enrolled names to the database
            _context.Enrollment.Add(enrollment);
            //Saving the entry
            _context.SaveChanges();

            //Redirect to details action
            return(RedirectToAction("Details"));
        }