Exemplo n.º 1
0
        public ActionResult Create(Student student, string Subject_ID)
        {
            Subject_Student list = new Subject_Student();

            list = new Subject_Student
            {
                Subject_ID = Subject_ID,
                Roll       = student.Roll
            };
            if (ModelState.IsValid)
            {
                if (unitOfWork.Subject.CheckExitsSubject(Subject_ID))
                {
                    if (unitOfWork.Students.IsExtisStudent(student.Roll) &&
                        unitOfWork.Subject.IsExitsSubject(Subject_ID))
                    {
                        unitOfWork.SubjectStudent.Insert(list);
                        // unitOfWork.ClassStudent.Insert(getRow.GetClassStudent(rows));
                    }
                    else
                    if (!unitOfWork.Students.CheckExitsStudent(student.Roll))
                    {
                        unitOfWork.Students.Insert(student);
                        unitOfWork.SubjectStudent.Insert(list);
                        //unitOfWork.ClassStudent.Insert(getRow.GetClassStudent(rows));
                    }
                }
                //unitOfWork.Students.Insert(student);
                unitOfWork.Save();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Exemplo n.º 2
0
        public ActionResult Create(Student student, string Subject_ID, string Campus_ID)
        {
            GetListSelect();
            student.Campus_ID = Campus_ID;
            Subject_Student list = new Subject_Student();

            list = new Subject_Student
            {
                Subject_ID  = Subject_ID,
                Roll        = student.Roll,
                Semester_ID = student.Semester_ID
            };
            if (ModelState.IsValid)
            {
                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                if (!string.IsNullOrEmpty(student.Email))
                {
                    Match match = regex.Match(student.Email.Trim());
                    if (!match.Success)
                    {
                        ViewBag.Error = "Email invalid!";
                        return(View(student));
                    }
                }
                if (unitOfWork.Subject.CheckExitsSubject(Subject_ID))
                {
                    if (unitOfWork.Students.IsExtisStudent(student.Roll, student.Semester_ID) &&
                        unitOfWork.Subject.IsExitsSubject(Subject_ID))
                    {
                        if (unitOfWork.SubjectStudent.IsExitsSubjectStudent(student.Roll, student.Semester_ID, Subject_ID))
                        {
                            ViewBag.Error = "Student  " + student.Roll + " has registered for subject " + Subject_ID;
                            return(View(student));
                        }
                        unitOfWork.SubjectStudent.Insert(list);
                    }
                    else
                    if (!unitOfWork.Students.IsExtisStudent(student.Roll, student.Semester_ID))
                    {
                        unitOfWork.Students.Insert(student);
                        unitOfWork.SubjectStudent.Insert(list);
                    }
                }
                unitOfWork.Save();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Exemplo n.º 3
0
        public ActionResult Enroll(int id_subject)
        {
            // Recibe por post el id de la materia y trata de inscribirte a la misma
            try
            {
                using (Models.DBContainer db = new Models.DBContainer())
                {
                    int id_student = ((Student)Session["User"]).id_student;

                    // Esto es lo mismo de un metodo anterior que esta arriba... hacer alguna funcion para no repetir el codigo
                    // Veo si el alumno ya está inscripto en la materia revisando los registros
                    // de la tabla Subjects_Students
                    var course = (from sub_stu in db.Subjects_Students
                                  where sub_stu.id_student == id_student && sub_stu.id_subject == id_subject
                                  select sub_stu).FirstOrDefault();

                    if (course != null)
                    {
                        // El estudiante ya está inscripto, mandar a la lista de materias con un mensaje
                        ViewData["EnrollMessage"] = "You're already enrolled in this subject";
                        ViewData["TypeMessage"]   = "alert-warning";
                        return(View());
                    }

                    // Obtengo la lista de los horarios de todas las materias en las que el
                    // estudiante se inscribió
                    var lst_schedules = (from subject in db.Subjects
                                         join sub_stu in db.Subjects_Students
                                         on subject.id_subject equals sub_stu.id_subject
                                         where sub_stu.id_student == id_student
                                         select new Schedule
                    {
                        time_from = subject.time_from,
                        time_to = subject.time_to
                    }).ToList();

                    // Obtengo el horario de la materia a la cual se desea inscribir
                    var subject_schedule = (from subject in db.Subjects
                                            where subject.id_subject == id_subject
                                            select new Schedule
                    {
                        time_from = subject.time_from,
                        time_to = subject.time_to
                    }).FirstOrDefault();

                    if (subject_schedule == null)
                    {
                        ViewData["EnrollMessage"] = "An error occurred, try again later";
                        ViewData["TypeMessage"]   = "alert-danger";
                        return(View());
                    }

                    // Recorro la lista de horarios de las inscripciones del estudiante
                    // buscando si hay algun solapamiento de horarios
                    foreach (var schedule in lst_schedules)
                    {
                        if (StartsInMiddle(schedule, subject_schedule) ||
                            StartsInMiddle(subject_schedule, schedule))
                        {
                            ViewData["EnrollMessage"] = "This course overlaps with any other subject that you already enrolled. You can't enroll in this course";
                            ViewData["TypeMessage"]   = "alert-info";
                            return(View());
                        }
                    }

                    // Si llegó hasta acá significa que no hay horarios solapados...
                    // Inscribirlo en la materia

                    Subject_Student new_subject_student = new Subject_Student();
                    new_subject_student.id_student = ((Student)Session["User"]).id_student;
                    new_subject_student.id_subject = id_subject;

                    db.Subjects_Students.Add(new_subject_student);
                    db.SaveChanges();
                }
                ViewData["EnrollMessage"] = "The enrollment has been successful";
                ViewData["TypeMessage"]   = "alert-success";
                return(View());
            }
            catch
            {
                ViewData["EnrollMessage"] = "An error occurred, try again later";
                ViewData["TypeMessage"]   = "alert-danger";
                return(View());
            }
        }