Beispiel #1
0
        public PartialViewResult ListByGroup(Guid semGroupId)
        {
            var semGroup = Db.SemesterGroups.SingleOrDefault(g => g.Id == semGroupId);

            var semester    = SemesterService.GetSemester(DateTime.Today);
            var vorSemester = SemesterService.GetPreviousSemester(semester);

            var model = new List <StudentViewModel>();

            if (semGroup != null)
            {
                var semSubService = new SemesterSubscriptionService();

                foreach (var sub in semGroup.Subscriptions)
                {
                    var user = UserManager.FindById(sub.UserId);

                    if (user != null)
                    {
                        var studModel = new StudentViewModel
                        {
                            User = user,
                            CurrentSubscription = semSubService.GetSubscription(user.Id, semester.Id),
                            LastSubscription    = semSubService.GetSubscription(user.Id, vorSemester.Id)
                        };



                        // alle Kurse des Benutzers
                        var courses =
                            Db.Activities.OfType <Course>()
                            .Where(c => c.Occurrence.Subscriptions.Any(s => s.UserId.Equals(user.Id)) &&
                                   c.SemesterGroups.Any((g => g.Semester.Id == semester.Id)))
                            .OrderBy(c => c.Name)
                            .ToList();


                        studModel.AllCourses = courses;

                        var coursesFit =
                            Db.Activities.OfType <Course>()
                            .Where(c => c.Occurrence.Subscriptions.Any(s => s.UserId.Equals(user.Id)) &&
                                   c.SemesterGroups.Any((g => g.Id == semGroupId)))
                            .OrderBy(c => c.Name)
                            .ToList();


                        studModel.CoursesFit = coursesFit;

                        model.Add(studModel);
                    }
                }
            }

            model = model.OrderBy(u => u.User.LastName).ToList();

            ViewBag.CurrentSemester = semester;
            ViewBag.LastSemester    = vorSemester;

            return(PartialView("Persons", model));
        }
Beispiel #2
0
        public PartialViewResult Persons(string searchString)
        {
            var semester    = SemesterService.GetSemester(DateTime.Today);
            var vorSemester = new SemesterService().GetSemester(semester, 1);

            var model = new List <StudentViewModel>();

            if (!string.IsNullOrEmpty(searchString))
            {
                var userDb = new ApplicationDbContext();
                var users  = from s in userDb.Users select s;
                if (!string.IsNullOrEmpty(searchString))
                {
                    users = users.Where(u =>
                                        u.MemberState == MemberState.Student &&
                                        (u.FirstName.ToUpper().Contains(searchString.ToUpper()) ||
                                         u.LastName.ToUpper().Contains(searchString.ToUpper()))
                                        );
                }


                var semSubService = new SemesterSubscriptionService();

                foreach (var user in users)
                {
                    var studModel = new StudentViewModel
                    {
                        User = user,
                        CurrentSubscription = semSubService.GetSubscription(user.Id, semester.Id),
                        LastSubscription    = semSubService.GetSubscription(user.Id, vorSemester.Id)
                    };

                    var semesterSubscription = Db.Subscriptions.OfType <SemesterSubscription>()
                                               .FirstOrDefault(s => s.SemesterGroup.Semester.Id == semester.Id && s.UserId.Equals(user.Id));

                    // alle Kurse des Benutzers
                    var courses =
                        Db.Activities.OfType <Course>()
                        .Where(c => c.Occurrence.Subscriptions.Any(s => s.UserId.Equals(user.Id)) &&
                               c.SemesterGroups.Any((g => g.Semester.Id == semester.Id)))
                        .OrderBy(c => c.Name)
                        .ToList();


                    studModel.AllCourses = courses;

                    var coursesFit = new List <Course>();

                    if (semesterSubscription != null)
                    {
                        coursesFit = Db.Activities.OfType <Course>()
                                     .Where(
                            c =>
                            c.Occurrence.Subscriptions.Any(s => s.UserId.Equals(user.Id)) &&
                            c.SemesterGroups.Any((g => g.Id == semesterSubscription.SemesterGroup.Id)))
                                     .OrderBy(c => c.Name)
                                     .ToList();
                    }


                    studModel.CoursesFit = coursesFit;

                    model.Add(studModel);
                }
            }

            model = model.OrderBy(u => u.User.LastName).ToList();

            ViewBag.CurrentSemester = semester;
            ViewBag.LastSemester    = vorSemester;

            return(PartialView("Persons", model));
        }