Exemplo n.º 1
0
        public ActionResult Courses(Guid moduleId, Guid?semId)
        {
            if (semId == null)
            {
                semId = SemesterService.GetSemester(DateTime.Today).Id;
            }

            var module   = Db.CurriculumModules.SingleOrDefault(x => x.Id == moduleId);
            var semester = SemesterService.GetSemester(semId);

            var courseSummaryService = new CourseService(Db);

            var model = new ModuleSemesterCoursesModel
            {
                Module   = module,
                Semester = semester
            };

            foreach (var moduleCourse in module.ModuleCourses)
            {
                var courses =
                    moduleCourse.Nexus.Where(x => x.Course.SemesterGroups.Any(g => g.Semester.Id == semId))
                    .Select(x => x.Course).Distinct().ToList();

                foreach (var course in courses)
                {
                    var summary = courseSummaryService.GetCourseSummary(course);

                    var semCourse = new ModuleSemesterCourseModel()
                    {
                        ModuleCourse  = moduleCourse,
                        CourseSummary = summary
                    };

                    model.Courses.Add(semCourse);
                }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public FileResult Download(Guid moduleId, Guid semId)
        {
            var module   = Db.CurriculumModules.SingleOrDefault(x => x.Id == moduleId);
            var semester = SemesterService.GetSemester(semId);

            var courseSummaryService = new CourseService(Db);

            var model = new ModuleSemesterCoursesModel
            {
                Module   = module,
                Semester = semester
            };


            foreach (var moduleCourse in module.ModuleCourses)
            {
                var courses =
                    moduleCourse.Nexus.Where(x => x.Course.SemesterGroups.Any(g => g.Semester.Id == semId))
                    .Select(x => x.Course).Distinct().ToList();


                foreach (var course in courses)
                {
                    var summary = courseSummaryService.GetCourseSummary(course);

                    var semCourse = new ModuleSemesterCourseModel()
                    {
                        ModuleCourse  = moduleCourse,
                        CourseSummary = summary
                    };

                    model.Courses.Add(semCourse);



                    foreach (var subscription in course.Occurrence.Subscriptions)
                    {
                        var participant = model.Participants.SingleOrDefault(x => x.UserId.Equals(subscription.UserId));

                        if (participant == null)
                        {
                            participant = new ModuleParticipantModel
                            {
                                UserId = subscription.UserId
                            };
                            model.Participants.Add(participant);
                        }

                        participant.Courses.Add(new ModuleParticipantSubscriptionModel
                        {
                            Course       = course,
                            Subscription = subscription
                        });
                    }
                }
            }

            // die user und students ergänzen
            foreach (var participant in model.Participants)
            {
                var user    = UserManager.FindById(participant.UserId);
                var student = user != null?StudentService.GetCurrentStudent(user) : null;

                participant.User    = user;
                participant.Student = student;
            }


            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms, Encoding.Default);

            writer.Write(
                "Name;Vorname;Studiengang;Semester;E-Mail");

            foreach (var modelCourse in model.Courses)
            {
                writer.Write(";{0}", modelCourse.CourseSummary.Course.ShortName);
            }

            writer.Write(Environment.NewLine);

            foreach (var participant in model.Participants)
            {
                if (participant.User != null)
                {
                    var student = participant.Student;
                    var group   = "";
                    var sem     = "";

                    if (student != null)
                    {
                        group = student.Curriculum.ShortName;
                        sem   = student.FirstSemester.Name;
                    }


                    writer.Write("{0};{1};{2};{3};{4}",
                                 participant.User.LastName, participant.User.FirstName,
                                 group, sem,
                                 participant.User.Email);

                    foreach (var modelCourse in model.Courses)
                    {
                        var pc = participant.Courses.FirstOrDefault(x => x.Course.Id == modelCourse.CourseSummary.Course.Id);

                        if (pc == null)
                        {
                            writer.Write(";");
                        }
                        else
                        {
                            if (pc.Subscription.OnWaitingList)
                            {
                                writer.Write(";WL");
                            }
                            else
                            {
                                writer.Write(";TN");
                            }
                        }
                    }

                    writer.Write(Environment.NewLine);
                }
            }

            writer.Flush();
            writer.Dispose();



            var sb = new StringBuilder();

            sb.Append("Eintragungen");
            sb.Append(module.ShortName);
            sb.Append("_");
            sb.Append(DateTime.Today.ToString("yyyyMMdd"));
            sb.Append(".csv");

            return(File(ms.GetBuffer(), "text/csv", sb.ToString()));
        }
Exemplo n.º 3
0
        public ActionResult Participants(Guid moduleId, Guid semId)
        {
            var module   = Db.CurriculumModules.SingleOrDefault(x => x.Id == moduleId);
            var semester = SemesterService.GetSemester(semId);

            var courseSummaryService = new CourseService(Db);

            var model = new ModuleSemesterCoursesModel
            {
                Module   = module,
                Semester = semester
            };


            foreach (var moduleCourse in module.ModuleCourses)
            {
                var courses =
                    moduleCourse.Nexus.Where(x => x.Course.SemesterGroups.Any(g => g.Semester.Id == semId))
                    .Select(x => x.Course).Distinct().ToList();


                foreach (var course in courses)
                {
                    var summary = courseSummaryService.GetCourseSummary(course);

                    var semCourse = new ModuleSemesterCourseModel()
                    {
                        ModuleCourse  = moduleCourse,
                        CourseSummary = summary
                    };

                    model.Courses.Add(semCourse);



                    foreach (var subscription in course.Occurrence.Subscriptions)
                    {
                        var participant = model.Participants.SingleOrDefault(x => x.UserId.Equals(subscription.UserId));

                        if (participant == null)
                        {
                            participant = new ModuleParticipantModel
                            {
                                UserId = subscription.UserId
                            };
                            model.Participants.Add(participant);
                        }

                        participant.Courses.Add(new ModuleParticipantSubscriptionModel {
                            Course       = course,
                            Subscription = subscription
                        });
                    }
                }
            }

            // die user und students ergänzen
            foreach (var participant in model.Participants)
            {
                var user    = UserManager.FindById(participant.UserId);
                var student = user != null?StudentService.GetCurrentStudent(user) : null;

                participant.User    = user;
                participant.Student = student;
            }

            return(View(model));
        }