diff --git a/Gordon360/Controllers/ScheduleController.cs b/Gordon360/Controllers/ScheduleController.cs index 265e9ad15..25f002e49 100644 --- a/Gordon360/Controllers/ScheduleController.cs +++ b/Gordon360/Controllers/ScheduleController.cs @@ -122,7 +122,6 @@ public async Task> GetAsync(string username, [FromQuery] st /// /// A IEnumerable of session objects as well as the schedules [HttpGet] - [AllowAnonymous] [Route("{username}/allcourses")] public async Task> GetAllCourses(string username) { diff --git a/Gordon360/Models/ViewModels/UserCoursesViewModel.cs b/Gordon360/Models/ViewModels/UserCoursesViewModel.cs index 4f17c2a71..02011cc91 100644 --- a/Gordon360/Models/ViewModels/UserCoursesViewModel.cs +++ b/Gordon360/Models/ViewModels/UserCoursesViewModel.cs @@ -9,8 +9,6 @@ namespace Gordon360.Models.ViewModels public class UserCoursesViewModel { public string UserID { get; set; } - public int STUDENT_ID { get; set; } - public int? INSTRUCTOR_ID { get; set; } public string SessionCode { get; set; } public string CRS_CDE { get; set; } public string CRS_TITLE { get; set; } @@ -42,8 +40,6 @@ public static implicit operator UserCoursesViewModel(UserCourses course) UserCoursesViewModel vm = new UserCoursesViewModel { UserID =course.UserID, - STUDENT_ID = course.STUDENT_ID, - INSTRUCTOR_ID = course.INSTRUCTOR_ID, SessionCode = code, CRS_CDE = course.CRS_CDE, CRS_TITLE = course.CRS_TITLE, diff --git a/Gordon360/Services/ScheduleService.cs b/Gordon360/Services/ScheduleService.cs index 7f0440025..58fc37552 100644 --- a/Gordon360/Services/ScheduleService.cs +++ b/Gordon360/Services/ScheduleService.cs @@ -108,12 +108,14 @@ public async Task> GetAllCourses(string use { throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found." }; } - var allSessions = _sessionService.GetAll(); var result = Enumerable.Empty(); var allSchedule = _context.UserCourses - .Where(s => s.UserID == account.gordon_id).OrderByDescending(s => s.YR_CDE); - + .Where(s => s.UserID == account.gordon_id) + .Select(s => (UserCoursesViewModel)s) + .ToList() + .OrderByDescending(course => course.SessionCode) + .DistinctBy(s => s.CRS_CDE); foreach (SessionViewModel vm in allSessions) { @@ -124,7 +126,7 @@ public async Task> GetAllCourses(string use SessionDescription = vm.SessionDescription, SessionBeginDate = vm.SessionBeginDate, SessionEndDate = vm.SessionEndDate, - AllCourses = allSchedule.Select(s => (UserCoursesViewModel)s) + AllCourses = allSchedule.Where(s => s.SessionCode == vm.SessionCode) }); } return result;