Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 4
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));
        }