Added browse page and state-filtering functionality

This commit is contained in:
Joshua Deck 2024-08-26 09:21:40 -04:00
parent b0739e019a
commit 3d5c720a5d
6 changed files with 1505 additions and 2 deletions

View File

@ -51,6 +51,43 @@ namespace TSC2.Components.CSharp
public static List<Tuple<string, string, string, float>> FilterByState(string state)
{
List<Tuple<string, string, string, float>> results = new();
MySqlConnection conn = new MySqlConnection(_connectionString);
conn.Open();
using (var cmd = new MySqlCommand("SELECT * FROM shopinformation WHERE address LIKE CONCAT('%', @state, ',%');", conn))
{
cmd.Parameters.AddWithValue("@state", state);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
Console.WriteLine("Executed filter");
while (reader.Read())
{
Console.WriteLine("Result found");
var uniqueID = reader.GetString(0);
var shopName = reader.GetString(1);
var address = reader.GetString(2);
var score = 5.0f; // TODO: replace with average lookup. Will require a query or new field on each shop in the db
//var phone = reader.GetString(3);
//var website = reader.GetString(4);
//var hours = reader.GetString(5);
//var about = reader.GetString(6);
//double latitude = reader.GetDouble(7);
//double longitude = reader.GetDouble(8);
Tuple<string, string, string, float> tuple = new Tuple<string, string, string, float>(uniqueID, shopName, address, score);
results.Add(tuple);
}
}
}
return results;
}
/**********************************************/
// LOGIN FLOW
/**********************************************/

View File

@ -44,7 +44,7 @@
<ul class="menu-container">
<li class="menu-item current"><a class="menu-link" href=""><div>Home</div></a></li>
<!-- Mega Menu -->
<li class="menu-item"><a class="menu-link" href="/info"><div>Browse By State</div></a></li>
<li class="menu-item"><a class="menu-link" href="/browse"><div>Browse By State</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-dealers.html"><div>Dealers</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-accessories.html"><div>Accessories</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-interiors.html"><div>Interiors</div></a></li>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,38 @@
@page "/browse/{State}"
@using TSC2.Components.CSharp;
<h1>@State</h1>
<h2>@results</h2>
<ul>
@foreach(Tuple<string, string, string, float> current in filterResults)
{
<li><a href="/info/@current.Item2&@current.Item1">@current.Item4 * | @current.Item2 | @current.Item3</a></li>
}
</ul>
@code {
[Parameter]
public string State { get; set; } = "MI";
private string results = "No results found.";
private List<Tuple<string,string,string,float>> filterResults = new();
protected override Task OnInitializedAsync()
{
filterResults = DatabaseManager.FilterByState(State);
if (filterResults.Count == 0)
return Task.FromResult(0);
this.results = "Results:\n";
return Task.FromResult(0);
/*foreach (Tuple<string, string, string, float> current in results)
{
}*/
}
}

View File

@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageReference Include="MySql.Data" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Telerik.UI.for.Blazor" Version="6.0.2" />
<PackageReference Include="Telerik.UI.for.Blazor" Version="6.2.0" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties UseCdnSupport="False" UseFontIcons="True" /></VisualStudio></ProjectExtensions>
</Project>

File diff suppressed because it is too large Load Diff