diff --git a/UWLecturePlan/Controllers/LectureController.cs b/UWLecturePlan/Controllers/LectureController.cs index 9389891..ec2533a 100644 --- a/UWLecturePlan/Controllers/LectureController.cs +++ b/UWLecturePlan/Controllers/LectureController.cs @@ -25,6 +25,7 @@ namespace UWLecturePlan.Controllers model.LectureEvents = db.LectureEvents.Include(x=>x.Lecture) .Where(x => x.From >= from) .Where(x => x.Lecture.Semester == model.CurrentSemester) + .Where(x => x.Lecture.Branch == model.BranchFilter || model.BranchFilter == null) .ToList(); if (model.LocationFilter != null) @@ -33,6 +34,8 @@ namespace UWLecturePlan.Controllers .Where(x => x.Location.Contains(model.LocationFilter)).ToList(); } + model.Branches = db.LectureEvents.Select(x => x.Lecture.Branch).Distinct().OrderBy(x=>x).ToList(); + return View(model); } diff --git a/UWLecturePlan/Models/LecturesViewModel.cs b/UWLecturePlan/Models/LecturesViewModel.cs index 145147b..cd7850a 100644 --- a/UWLecturePlan/Models/LecturesViewModel.cs +++ b/UWLecturePlan/Models/LecturesViewModel.cs @@ -7,8 +7,12 @@ namespace UWLecturePlan.Models public string CurrentSemester { get; set; } - public string LocationFilter { get; set; } + public string? LocationFilter { get; set; } - public List LectureEvents { get; set; } + public string? BranchFilter { get; set; } + + public List LectureEvents { get; set; } + + public List Branches { get; set; } } } diff --git a/UWLecturePlan/Views/Lecture/Index.cshtml b/UWLecturePlan/Views/Lecture/Index.cshtml index b6eb6fb..d910399 100644 --- a/UWLecturePlan/Views/Lecture/Index.cshtml +++ b/UWLecturePlan/Views/Lecture/Index.cshtml @@ -1,4 +1,21 @@ -@model LecturesViewModel +@using System.Text.RegularExpressions +@model LecturesViewModel +@{ + string GetBranchName(string branch) + { + Regex regex = new Regex(@".* - (.*)"); + + var match = regex.Match(branch); + if (match.Success) + { + return match.Groups[1].Value; + } + else + { + return branch; + } + } +}