public ActionResult Courses() { var user = GetCurrentUser(); var courses = Db.Activities.OfType <Course>().Where(x => x.Owners.Any(o => o.Member.UserId.Equals(user.Id)) || x.Dates.Any(d => d.Hosts.Any(h => !string.IsNullOrEmpty(h.UserId) && h.UserId.Equals(user.Id)))).ToList(); var model = new LecturerSummaryModel(); foreach (var c in courses) { var orderedDates = c.Dates.OrderBy(x => x.Begin).ToList(); var firstDate = orderedDates.FirstOrDefault(); var lastDate = orderedDates.LastOrDefault(); var owner = c.Owners.FirstOrDefault(o => !string.IsNullOrEmpty(o.Member.UserId) && o.Member.UserId.Equals(user.Id)); var dates = c.Dates.Where(x => x.Hosts.Any(h => !string.IsNullOrEmpty(h.UserId) && h.UserId.Equals(user.Id))).ToList(); var courseModel = new LecturerCourseSummaryModel { Course = c, FirstDate = firstDate, LastDate = lastDate, Owner = owner, HostingDates = dates }; model.Courses.Add(courseModel); } return(View(model)); }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult OfficeHour(Guid?id) { var user = GetCurrentUser(); var infoService = new OfficeHourInfoService(UserManager); if (id == null) { var summaryModel = new LecturerSummaryModel() { Memberships = MemberService.GetFacultyMemberships(user.Id) }; var officeHours = Db.Activities.OfType <OfficeHour>().Where(x => x.Owners.Any(o => !string.IsNullOrEmpty(o.Member.UserId) && o.Member.UserId.Equals(user.Id))) .ToList(); foreach (var oh in officeHours) { var ohModel = new LecturerOfficehourSummaryModel() { OfficeHour = oh }; summaryModel.OfficeHours.Add(ohModel); } var semester = SemesterService.GetSemester(DateTime.Today); ViewBag.ThisSemester = semester; ViewBag.NextSemester = SemesterService.GetNextSemester(semester); return(View(summaryModel)); } var officeHour = Db.Activities.OfType <OfficeHour>().SingleOrDefault(x => x.Id == id.Value); var model = new OfficeHourSubscriptionViewModel { OfficeHour = officeHour, Semester = officeHour.Semester, Host = infoService.GetHost(officeHour), }; if (officeHour.ByAgreement) { return(View("DateListAgreement", model)); } model.Dates.AddRange(infoService.GetDates(officeHour)); return(View("DateList", model)); }