Skip to content

Commit

Permalink
Further updates from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
RossClark01 committed Dec 11, 2024
1 parent 0c03cf7 commit 8d1d067
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 69 deletions.
5 changes: 5 additions & 0 deletions Gordon360/Controllers/HousingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ public async Task<IActionResult> IsRAOnCall([FromRoute] string raId)
return Ok(new { IsOnCall = isOnCall });
}

/// <summary>
/// Checks if a student is residential
/// </summary>
/// <param name="idNum">The ID of the student</param>
/// <returns>True if the student is a resident</returns>
[HttpGet]
[Route("students/{idNum}/is-residential")]
public async Task<IActionResult> IsStudentResidential([FromRoute] int idNum)
Expand Down
32 changes: 27 additions & 5 deletions Gordon360/Documentation/Gordon360.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gordon360/Models/CCT/Context/CCTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public CCTContext(DbContextOptions<CCTContext> options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("GORDON\\Ross.Clark");

modelBuilder.Entity<ACCOUNT>(entity =>
{
Expand Down
4 changes: 3 additions & 1 deletion Gordon360/Models/CCT/Context/efpt.CCT.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
"UseAsyncStoredProcedureCalls": true,
"UseBoolPropertiesWithoutDefaultSql": false,
"UseDatabaseNames": true,
"UseDatabaseNamesForRoutines": true,
"UseDateOnlyTimeOnly": false,
"UseDbContextSplitting": false,
"UseDecimalDataAnnotationForSprocResult": true,
Expand All @@ -438,5 +439,6 @@
"UseSchemaFolders": true,
"UseSchemaNamespaces": false,
"UseSpatial": false,
"UseT4": false
"UseT4": false,
"UseT4Split": false
}
8 changes: 2 additions & 6 deletions Gordon360/Models/CCT/Housing/Hall_Assignment_Ranges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ public partial class Hall_Assignment_Ranges
[Unicode(false)]
public string Hall_ID { get; set; }

[StringLength(10)]
[Unicode(false)]
public string Room_Start { get; set; }
public int Room_Start { get; set; }

[StringLength(10)]
[Unicode(false)]
public string Room_End { get; set; }
public int Room_End { get; set; }

[InverseProperty("Range")]
public virtual ICollection<RA_Assigned_Ranges> RA_Assigned_Ranges { get; set; } = new List<RA_Assigned_Ranges>();
Expand Down
7 changes: 6 additions & 1 deletion Gordon360/Models/CCT/Housing/Hall_Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ public partial class Hall_Tasks
[Unicode(false)]
public string Hall_ID { get; set; }

[Column(TypeName = "datetime")]
public DateTime Task_Date { get; set; }

public bool Is_Recurring { get; set; }

public bool Is_Completed { get; set; }

public DateTime? Completed_At { get; set; }

[StringLength(10)]
[Unicode(false)]
public string Completed_By { get; set; }
}
2 changes: 0 additions & 2 deletions Gordon360/Models/CCT/Housing/RA_On_Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public partial class RA_On_Call
[Unicode(false)]
public string Ra_ID { get; set; }

[Column(TypeName = "datetime")]
public DateTime Check_in_time { get; set; }

[Column(TypeName = "datetime")]
public DateTime? Check_out_time { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HallAssignmentRangeViewModel
{
public int RangeID { get; set; } //ID of room range
public string Hall_ID { get; set; } // ID for the hall (e.g., "Chase")
public string Room_Start { get; set; } // Start room number (e.g., "101")
public string Room_End { get; set; } // End room number (e.g., "120")
public int Room_Start { get; set; } // Start room number (e.g., 101)
public int Room_End { get; set; } // End room number (e.g., 120)
}
}
100 changes: 48 additions & 52 deletions Gordon360/Services/HousingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,17 @@ public bool ChangeApplicationDateSubmitted(int applicationID)
public async Task<Hall_Assignment_Ranges> CreateRoomRangeAsync(HallAssignmentRangeViewModel model)
{

// Room_Start and Room_End are integers
if (!int.TryParse(model.Room_Start, out int roomStart) || !int.TryParse(model.Room_End, out int roomEnd))
{
throw new ArgumentException("Room_Start and Room_End must be integers.");
}

// Check if Room_End is greater than Room_Start
if (roomEnd <= roomStart)
if (model.Room_End <= model.Room_Start)
{
throw new ArgumentException("Room_End must be greater than Room_Start.");
}
// Check if there is any overlapping room ranges in the same hall
var overlappingRange = await context.Hall_Assignment_Ranges
.FirstOrDefaultAsync(r => r.Hall_ID == model.Hall_ID
&& ((string.Compare(r.Room_Start, model.Room_Start) <= 0 && string.Compare(r.Room_End, model.Room_Start) >= 0) ||
(string.Compare(r.Room_Start, model.Room_End) <= 0 && string.Compare(r.Room_End, model.Room_End) >= 0)));
&& ((r.Room_Start <= model.Room_Start && r.Room_End >= model.Room_Start) ||
(r.Room_Start <= model.Room_End && r.Room_End >= model.Room_End)));

if (overlappingRange != null)
{
Expand Down Expand Up @@ -613,8 +608,8 @@ public async Task<RA_Status_Schedule> CreateStatusAsync( RA_Status_ScheduleViewM
public async Task<bool> DeleteRoomRangeAsync(int rangeId)
{
// Find the room range by ID
var roomRange = await context.Hall_Assignment_Ranges
.FirstOrDefaultAsync(r => r.Range_ID == rangeId);
var roomRange = await context.Hall_Assignment_Ranges.FindAsync(rangeId);


if (roomRange == null)
{
Expand Down Expand Up @@ -732,8 +727,8 @@ public async Task<RA_StudentsViewModel> GetResidentRAAsync(string hallId, string
// Query the room range within the specified hall that contains the room number
var roomRange = await context.Hall_Assignment_Ranges
.FirstOrDefaultAsync(r => r.Hall_ID == hallId
&& string.Compare(r.Room_Start, roomNumber) <= 0
&& string.Compare(r.Room_End, roomNumber) >= 0);
&& r.Room_Start <= int.Parse(roomNumber)
&& r.Room_End >= int.Parse(roomNumber));

if (roomRange == null)
{
Expand Down Expand Up @@ -773,10 +768,9 @@ public async Task<RA_StudentsViewModel> GetResidentRAAsync(string hallId, string
throw new InvalidOperationException("RA details could not be retrieved.");
}

// Fetch the preferred contact method for the RA
// Fetch and include the preferred contact method for the RA
var preferredContact = await GetPreferredContactAsync(assignedRA.ID);

// Include the preferred contact in the returned model
assignedRA.PreferredContact = preferredContact;

return assignedRA;
Expand Down Expand Up @@ -868,7 +862,7 @@ public async Task<bool> SetPreferredContactMethodAsync(string raId, string prefe
else
{
// Create a new preference using the CCT entity
await context.RA_Pref_Contact.AddAsync(new RA_Pref_Contact
context.RA_Pref_Contact.Add(new RA_Pref_Contact
{
Ra_ID = raId,
Pref_contact = preferredContactMethod
Expand Down Expand Up @@ -964,21 +958,21 @@ public async Task<object> GetContactPreferenceAsync(string raId)
/// <returns>The ID of the on-call RA, or null if no RA is currently on call</returns>
public async Task<RA_On_Call_GetViewModel> GetOnCallRAAsync(string Hall_ID)
{
var onCallRA = await context.Current_On_Call // Use your updated view name here
var onCallRA = await context.Current_On_Call
.Where(ra => ra.Hall_ID == Hall_ID) // Filter by Hall_ID and only active check-ins
.Select(ra => new RA_On_Call_GetViewModel
{
Hall_ID = ra.Hall_ID, // Hall ID
Hall_Name = ra.Hall_Name, // Hall name
RoomNumber = ra.RoomNumber, // RA's room number
RA_Name = ra.RA_Name, // RA's full name
PreferredContact = ra.PreferredContact, // Preferred contact method
Check_in_time = ra.Check_in_time, // Check-in time
RD_Email = ra.RD_Email, // RD's email
RD_Name = ra.RD_Name, // RD's name
RA_Profile_Link = ra.RA_Profile_Link, // RA's profile link
RD_Profile_Link = ra.RD_Profile_Link, // RD's profile link
RA_Photo = ra.RA_Photo // RA's Photo URL
Hall_ID = ra.Hall_ID,
Hall_Name = ra.Hall_Name,
RoomNumber = ra.RoomNumber,
RA_Name = ra.RA_Name,
PreferredContact = ra.PreferredContact,
Check_in_time = ra.Check_in_time,
RD_Email = ra.RD_Email,
RD_Name = ra.RD_Name,
RA_Profile_Link = ra.RA_Profile_Link,
RD_Profile_Link = ra.RD_Profile_Link,
RA_Photo = ra.RA_Photo
})
.FirstOrDefaultAsync();

Expand All @@ -988,11 +982,12 @@ public async Task<RA_On_Call_GetViewModel> GetOnCallRAAsync(string Hall_ID)
/// <summary>
/// Checks an RA in
/// </summary>
/// <param name="checkin">The viewmodel object of the RA checking in</param>
/// <param name="Ra_ID">Id of the ra checking in</param>
///<param name="Hall_IDs">The Hall(s) the RA is checking into</param>
/// <returns>true if RA checked in successfully</returns>
public async Task<bool> RA_CheckinAsync(string[] Hall_ID, string Ra_ID)
public async Task<bool> RA_CheckinAsync(string[] Hall_IDs, string Ra_ID)
{
foreach (string hallId in Hall_ID)
foreach (string hallId in Hall_IDs)
{
// Check if there is an existing RA checked into this hall without an end time
var existingRA = await context.RA_On_Call
Expand All @@ -1014,7 +1009,7 @@ public async Task<bool> RA_CheckinAsync(string[] Hall_ID, string Ra_ID)
Check_in_time = DateTime.Now,
Check_out_time = null // RA has an active checkin
};
await context.RA_On_Call.AddAsync(newCheckin);
context.RA_On_Call.Add(newCheckin);
}

await context.SaveChangesAsync();
Expand All @@ -1027,17 +1022,17 @@ public async Task<bool> RA_CheckinAsync(string[] Hall_ID, string Ra_ID)
/// <returns>The RAs on call</returns>
public async Task<List<RA_On_Call_GetViewModel>> GetOnCallRAAllHallsAsync()
{
var onCallRAs = await context.Current_On_Call // Use your updated view name here
var onCallRAs = await context.Current_On_Call
.Select(oncall => new RA_On_Call_GetViewModel
{
Hall_ID = oncall.Hall_ID,
Hall_Name = oncall.Hall_Name, // Hall name
RA_Name = oncall.RA_Name, // RA's full name
PreferredContact = oncall.PreferredContact, // Preferred contact method
Check_in_time = oncall.Check_in_time, // Check-in time
RD_Email = oncall.RD_Email, // RD's email
RA_Profile_Link = oncall.RA_Profile_Link, // RA's profile link
RD_Profile_Link = oncall.RD_Profile_Link, // RD's profile link
Hall_Name = oncall.Hall_Name,
RA_Name = oncall.RA_Name,
PreferredContact = oncall.PreferredContact,
Check_in_time = oncall.Check_in_time,
RD_Email = oncall.RD_Email,
RA_Profile_Link = oncall.RA_Profile_Link,
RD_Profile_Link = oncall.RD_Profile_Link,
RD_Name = oncall.RD_Name,
RA_Photo = oncall.RA_Photo
})
Expand All @@ -1047,7 +1042,11 @@ public async Task<List<RA_On_Call_GetViewModel>> GetOnCallRAAllHallsAsync()
}



/// <summary>
/// Checks if an RA is currently on call.
/// </summary>
/// <param name="raId">The ID of the RA</param>
/// <returns>True if the RA is on call, false otherwise</returns>
public async Task<bool> IsRAOnCallAsync(string raId)
{
// Check if the RA is currently on call
Expand All @@ -1056,20 +1055,17 @@ public async Task<bool> IsRAOnCallAsync(string raId)

return isOnCall;
}

/// <summary>
/// Checks if a student is residential
/// </summary>
/// <param name="idNum">The ID of the student</param>
/// <returns>True if the student is a resident</returns>
public async Task<bool> IsStudentResidentialAsync(int idNum)
{
var student = await Task.FromResult(
context.ResidentialStatus_View
.Where(s => s.Student_ID == idNum)
.Select(s => s.Is_Residential)
.FirstOrDefault()
);

if (student == null)
{
throw new InvalidOperationException("Student details could not be retrieved.");
}
var student = await context.ResidentialStatus_View
.Where(s => s.Student_ID == idNum)
.Select(s => s.Is_Residential)
.FirstOrDefaultAsync();

return student == 1;
}
Expand Down

0 comments on commit 8d1d067

Please sign in to comment.