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
20 changes: 5 additions & 15 deletions PC2/Data/AgencyDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,11 @@ public static async Task<List<Agency>> GetAllAgenciesAsync(ApplicationDbContext
/// </summary>
public static async Task<List<Agency>> GetSpecificAgenciesAsync(ApplicationDbContext context, int categoryID)
{
List<Agency> agencies = await GetAllAgenciesAsync(context);

List<Agency> result = new List<Agency>();
for (int i = 0; i < agencies.Count; i++)
{
for (int j = 0; j < agencies[i].AgencyCategories.Count; j++)
{
if (agencies[i].AgencyCategories[j].AgencyCategoryId == categoryID)
{
result.Add(agencies[i]);
}
}
}

return result;
return await context.Agency
.Include(nameof(Agency.AgencyCategories))
.Where(agency => agency.AgencyCategories.Any(cat => cat.AgencyCategoryId == categoryID))
.OrderBy(agency => agency.AgencyName)
.ToListAsync();
}

/// <summary>
Expand Down
99 changes: 3 additions & 96 deletions PC2/Views/Resources/ResourceGuide.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,12 @@ else

@if (Model.Agencies[i].Email != null)
{
string email = Model.Agencies[i].Email;
int emailStart = 0;

@*separate multiple emails*@
@for (int j = 0; j < email.Length; j++)
@foreach (string singleEmail in Model.Agencies[i].Email.Split(' ', StringSplitOptions.RemoveEmptyEntries))
{
// if the email contains a space
if (email[j] == ' ')
{
// display all characters from emailStart to current index as link
string singleEmail = email.Substring(emailStart, j - emailStart);
<a href="mailto:@singleEmail">@singleEmail</a>
<a href="mailto:@singleEmail.Trim()">@singleEmail.Trim()</a>
<br>
emailStart = j;
}
}
// display link as final email
string finalEmail = email.Substring(emailStart, email.Length - emailStart);

<a href="mailto:@finalEmail.Trim()">@finalEmail</a>
}
</div>

<div class="col-md-1 col-2">
Expand All @@ -263,85 +248,7 @@ else
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<dl class="row">
@*For each property in class agency*@
@foreach(var prop in typeof(Agency).GetProperties())
{

if (prop.GetValue(Model.Agencies[i]) != null)
{
// handles email links
if (prop.Name == "Email")
{
<dt>@prop.Name</dt>
string emailData = prop.GetValue(Model.Agencies[i]).ToString();
@*separate multiple emails*@
<dd>
@{
if (emailData != null)
{
string[] emails = emailData.Split(' ');
foreach(string email in emails)
{
<a href="mailto:@email.Trim()">
@email
</a>
<br>
}
}
}
</dd>
}
// handles phone links
else if (prop.Name == "Phone")
{
<dt>@prop.Name</dt>
<dd>
@Html.Raw(PC2.Models.RendererHelper.RenderPhone(prop.GetValue(Model.Agencies[i])?.ToString()))
</dd>
}

// handles website links
else if (prop.Name == "Website")
{
<dt>@prop.Name</dt>
string websiteString = prop.GetValue(Model.Agencies[i]).ToString();

if (websiteString != null)
{
string[] websites = websiteString.Split(' ');
foreach(string website in websites)
{
string url = website.Trim();
// if the url is empty, skip it. This is to handle extra spaces in the data
if (url == string.Empty)
{
continue;
}
if (!url.StartsWith("https://") && !url.StartsWith("http://"))
{
url = "https://" + url;
}
<dd><a href="@url">@url</a></dd>
}
}
}
// excludes certain columns and displays the rest
else if (prop.Name != "AgencyCategories" && prop.Name != "AgencyId" && prop.Name != "AgencyName")
{
if (prop.Name == "Address1" && Model.Agencies[i].Address2 == null)
{
<dt>Address</dt>
}
else
{
<dt>@prop.Name</dt>
}
<dd>@prop.GetValue(Model.Agencies[i])</dd>
}
}
}
</dl>
@await Html.PartialAsync("_AgencyDetails", Model.Agencies[i])
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
Expand Down
126 changes: 126 additions & 0 deletions PC2/Views/Shared/_AgencyDetails.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
@model PC2.Models.Agency

@*
Partial view that renders the detail fields for a single Agency inside the modal body.
Each field is rendered explicitly (no reflection) so the output is easy to follow and maintain.
*@

<dl class="row">

@if (Model.AgencyName2 != null)
{
<dt>AgencyName2</dt>
<dd>@Model.AgencyName2</dd>
}

@if (Model.Contact != null)
{
<dt>Contact</dt>
<dd>@Model.Contact</dd>
}

@if (Model.Address1 != null)
{
<dt>@(Model.Address2 == null ? "Address" : "Address1")</dt>
<dd>@Model.Address1</dd>
}

@if (Model.Address2 != null)
{
<dt>Address2</dt>
<dd>@Model.Address2</dd>
}

@if (Model.City != null)
{
<dt>City</dt>
<dd>@Model.City</dd>
}

@if (Model.State != null)
{
<dt>State</dt>
<dd>@Model.State</dd>
}

@if (Model.Zip != null)
{
<dt>Zip</dt>
<dd>@Model.Zip</dd>
}

@if (Model.MailingAddress != null)
{
<dt>MailingAddress</dt>
<dd>@Model.MailingAddress</dd>
}

@if (Model.Phone != null)
{
<dt>Phone</dt>
<dd>@Html.Raw(PC2.Models.RendererHelper.RenderPhone(Model.Phone))</dd>
}

@if (Model.TollFree != null)
{
<dt>TollFree</dt>
<dd>@Model.TollFree</dd>
}

@if (Model.TTY != null)
{
<dt>TTY</dt>
<dd>@Model.TTY</dd>
}

@if (Model.TDD != null)
{
<dt>TDD</dt>
<dd>@Model.TDD</dd>
}

@if (Model.CrisisHelpHotline != null)
{
<dt>CrisisHelpHotline</dt>
<dd>@Model.CrisisHelpHotline</dd>
}

@if (Model.Fax != null)
{
<dt>Fax</dt>
<dd>@Model.Fax</dd>
}

@if (Model.Email != null)
{
<dt>Email</dt>
<dd>
@foreach (string email in Model.Email.Split(' ', StringSplitOptions.RemoveEmptyEntries))
{
<a href="mailto:@email.Trim()">@email</a>
<br>
}
</dd>
}

@if (Model.Website != null)
{
@foreach (string website in Model.Website.Split(' ', StringSplitOptions.RemoveEmptyEntries))
{
string url = website.Trim();
if (!url.StartsWith("https://") && !url.StartsWith("http://"))
{
url = "https://" + url;
}
<dt>Website</dt>
<dd><a href="@url">@url</a></dd>
}
}

@if (Model.Description != null)
{
<dt>Description</dt>
<dd>@Model.Description</dd>
}

</dl>
Loading