Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Null File Label exception #395

Merged
merged 1 commit into from
May 13, 2024
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
13 changes: 5 additions & 8 deletions FMS.Domain/Dto/Cabinet/CabinetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ namespace FMS.Domain.Dto
{
public static class CabinetExtensions
{
public static List<string> GetCabinetsForFile(this IEnumerable<CabinetSummaryDto> cabinets, string fileLabel, bool testValidity = true)
{
if (testValidity)
public static List<string> GetCabinetsForFile(this IEnumerable<CabinetSummaryDto> cabinets, string fileLabel)
{
Prevent.NullOrEmpty(fileLabel, nameof(fileLabel));
if (!File.IsValidFileLabelFormat(fileLabel))
{
Prevent.NullOrEmpty(fileLabel, nameof(fileLabel));
if (!File.IsValidFileLabelFormat(fileLabel))
{
throw new ArgumentException($"File label '{fileLabel}' is invalid.", nameof(fileLabel));
}
throw new ArgumentException($"File label '{fileLabel}' is invalid.", nameof(fileLabel));
}

return cabinets.Where(e =>
Expand Down
7 changes: 4 additions & 3 deletions FMS.Infrastructure/Repositories/FacilityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@
var cabinets = await _context.GetCabinetListAsync(false);
foreach (var item in items)
{
bool test = item.FacilityType.Name != "RN" || !item.FileLabel.IsNullOrEmpty();

item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel, test);
if (!item.FileLabel.IsNullOrEmpty())
{
item.Cabinets = cabinets.GetCabinetsForFile(item.FileLabel);
}
}

var totalCount = await queried.CountAsync();
Expand Down Expand Up @@ -308,7 +309,7 @@
if (file == null)
throw new ArgumentException($"File Label {facilityUpdates.FileLabel} does not exist.");
facility.File = file;
facility.FileId = file?.Id;

Check warning on line 312 in FMS.Infrastructure/Repositories/FacilityRepository.cs

View workflow job for this annotation

GitHub Actions / Run unit tests

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)

Check warning on line 312 in FMS.Infrastructure/Repositories/FacilityRepository.cs

View workflow job for this annotation

GitHub Actions / Analyze with CodeQL (csharp)

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)
}
}

Expand Down
Loading