Skip to content

Commit

Permalink
modify code based on new view created for usercourses
Browse files Browse the repository at this point in the history
  • Loading branch information
mla04762 committed Jul 21, 2023
1 parent b92bdf4 commit ab1802b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gordon360/Controllers/ScheduleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public async Task<ActionResult<JArray>> GetAsync(string username, [FromQuery] st
/// </summary>
/// <returns>A IEnumerable of session objects as well as the schedules</returns>
[HttpGet]
[AllowAnonymous]
[Route("{username}/allcourses")]
public async Task<ActionResult<SessionCoursesViewModel>> GetAllCourses(string username)
{
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Models/ViewModels/SessionCoursesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SessionCoursesViewModel
public string SessionDescription { get; set; }
public Nullable<System.DateTime> SessionBeginDate { get; set; }
public Nullable<System.DateTime> SessionEndDate { get; set; }
public IEnumerable <ScheduleViewModel> AllCourses { get; set; }
public IEnumerable <UserCoursesViewModel> AllCourses { get; set; }
}


Expand Down
68 changes: 68 additions & 0 deletions Gordon360/Models/ViewModels/UserCoursesViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Gordon360.Models.CCT;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Graph;
using System;
using System.Runtime.Serialization.Formatters;

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; }
public string BLDG_CDE { get; set; }
public string ROOM_CDE { get; set; }
public string MONDAY_CDE { get; set; }
public string TUESDAY_CDE { get; set; }
public string WEDNESDAY_CDE { get; set; }
public string THURSDAY_CDE { get; set; }
public string FRIDAY_CDE { get; set; }
public string SATURDAY_CDE { get; set; }
public TimeSpan? BEGIN_TIME { get; set; }
public TimeSpan? END_TIME { get; set; }
public string Role { get; set; }
public static implicit operator UserCoursesViewModel(UserCourses course)
{
var code = course.YR_CDE;
if(course.TRM_CDE == "FA")
{
code += "09";
} else if (course.TRM_CDE == "SP")
{
code += "01";
} else
{
code += "05";
}

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,
BLDG_CDE = course.BLDG_CDE,
ROOM_CDE = course.ROOM_CDE,
MONDAY_CDE = course.MONDAY_CDE,
TUESDAY_CDE = course.TUESDAY_CDE,
WEDNESDAY_CDE = course.WEDNESDAY_CDE,
THURSDAY_CDE = course.THURSDAY_CDE,
FRIDAY_CDE = course.FRIDAY_CDE,
SATURDAY_CDE = course.SATURDAY_CDE,
BEGIN_TIME = course.BEGIN_TIME,
END_TIME = course.END_TIME,
Role = course.Role
};

return vm;
}
}


}
14 changes: 7 additions & 7 deletions Gordon360/Services/ScheduleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Gordon360.Services
{
Expand Down Expand Up @@ -102,14 +103,17 @@ public async Task<IEnumerable<ScheduleViewModel>> GetScheduleFacultyAsync(string
public async Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string username)

Check warning on line 103 in Gordon360/Services/ScheduleService.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var account = _context.ACCOUNT.FirstOrDefault(x => x.AD_Username == username);
var allSessions = _sessionService.GetAll();
var result = Enumerable.Empty<SessionCoursesViewModel>();

if (account == null)
{
throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found." };
}

var allSessions = _sessionService.GetAll();
var result = Enumerable.Empty<SessionCoursesViewModel>();
var allSchedule = _context.UserCourses
.Where(s => s.UserID == account.gordon_id).OrderByDescending(s => s.YR_CDE);


foreach (SessionViewModel vm in allSessions)
{
Expand All @@ -120,11 +124,7 @@ public async Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string use
SessionDescription = vm.SessionDescription,
SessionBeginDate = vm.SessionBeginDate,
SessionEndDate = vm.SessionEndDate,
//The case for "ALUMNI" does not work at the moment currently, but it doesn't affect the code,
//and might be used in the future, so we decided to leave it in.
AllCourses = account.account_type == "STUDENT" || account.account_type == "ALUMNI"
? await GetScheduleStudentAsync(username, vm.SessionCode)
: await GetScheduleFacultyAsync(username, vm.SessionCode),
AllCourses = allSchedule.Select(s => (UserCoursesViewModel)s)
});
}
return result;
Expand Down

0 comments on commit ab1802b

Please sign in to comment.