Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Core/Resgrid.Model/DepartmentNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public string TranslateBefore(List<CustomState> customStates = null)
switch ((EventTypes)EventType)
{
case EventTypes.UnitStatusChanged:
if (string.IsNullOrWhiteSpace(BeforeData))
return "Any";
Comment on lines +91 to +92
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n Core/Resgrid.Model/DepartmentNotification.cs | head -300

Repository: Resgrid/Core

Length of output: 9712


Use non-throwing parsing in these translation branches.

These guards fix the blank-data case, but lines 97, 126, 155, 217, 246, and 275 still use int.Parse on any other non-empty value. A legacy or partially corrupted notification row will still throw while rendering the page. Additionally, lines 157, 248, and 277 contain redundant parse calls that should also be made non-throwing.

Switch all these branches to int.TryParse with the current "Unknown"/"Any" sentinel fallback.

Suggested pattern
-						int id = int.Parse(BeforeData);
+						if (!int.TryParse(BeforeData, out var id))
+							return "Unknown";

Apply the same pattern to all instances in both TranslateBefore and TranslateCurrent methods.

Also applies to: 120-121, 149-150, 157, 211-212, 240-241, 248, 269-270, 277

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Core/Resgrid.Model/DepartmentNotification.cs` around lines 91 - 92, The
TranslateBefore and TranslateCurrent methods in DepartmentNotification use
int.Parse in multiple places (e.g., the branches around the
BeforeData/CurrentData checks and the parse calls referenced at lines noted in
your comment) which will throw on malformed data; replace every int.Parse usage
in these methods (including redundant double-parses) with int.TryParse and fall
back to the existing sentinel strings ("Any" for empty BeforeData, "Unknown"
where currently used) so invalid or legacy values do not throw—specifically
update all parse points in TranslateBefore and TranslateCurrent to attempt
TryParse into a local int and use the fallback when TryParse fails, and remove
duplicate parse calls by reusing the parsed result.

if (BeforeData == "-1")
return "Any";
else
Expand Down Expand Up @@ -115,6 +117,8 @@ public string TranslateBefore(List<CustomState> customStates = null)
}
break;
case EventTypes.PersonnelStaffingChanged:
if (string.IsNullOrWhiteSpace(BeforeData))
return "Any";
if (BeforeData == "-1")
return "Any";
else
Expand Down Expand Up @@ -142,6 +146,8 @@ public string TranslateBefore(List<CustomState> customStates = null)
}
break;
case EventTypes.PersonnelStatusChanged:
if (string.IsNullOrWhiteSpace(BeforeData))
return "None";
if (BeforeData == "-1")
return "Any";
else
Expand Down Expand Up @@ -202,6 +208,8 @@ public string TranslateCurrent(List<CustomState> customStates = null)
switch ((EventTypes)EventType)
{
case EventTypes.UnitStatusChanged:
if (string.IsNullOrWhiteSpace(CurrentData))
return "None";
if (CurrentData == "-1")
return "Any";
else
Expand Down Expand Up @@ -229,6 +237,8 @@ public string TranslateCurrent(List<CustomState> customStates = null)
}
break;
case EventTypes.PersonnelStaffingChanged:
if (string.IsNullOrWhiteSpace(CurrentData))
return "None";
if (CurrentData == "-1")
return "Any";
else
Expand Down Expand Up @@ -256,6 +266,8 @@ public string TranslateCurrent(List<CustomState> customStates = null)
}
break;
case EventTypes.PersonnelStatusChanged:
if (string.IsNullOrWhiteSpace(CurrentData))
return "None";
if (CurrentData == "-1")
return "Any";
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public async Task<IActionResult> Index()
var user = _usersService.GetUserById(userId);

if (sb.Length > 0)
sb.Append("," + UserHelper.GetFullNameForUser(user.UserId));
sb.Append("," + await UserHelper.GetFullNameForUser(user.UserId));
else
sb.Append(UserHelper.GetFullNameForUser(user.UserId));
sb.Append(await UserHelper.GetFullNameForUser(user.UserId));
}
}

Expand Down
Loading