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

Seed latitude and longitude for Grove City and Rock City Polaris. #431

Merged
merged 1 commit into from
Nov 15, 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
20 changes: 11 additions & 9 deletions BedBrigade.Client/Components/LocationGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ else
<SfTextBox @bind-Value=@location.BuildPostalCode Enabled="true" Placeholder="@_lc.Keys["BuildPostalCode"]" FloatLabelType="FloatLabelType.Auto" />
</div>
</div>
<div class="row">
<div class="col-md-4">
<SfNumericTextBox TValue="decimal?" Min=0.0m Max=360.0m Step=0.01m Format="n2" @bind-Value=@location.Latitude Enabled="true" Placeholder="@_lc.Keys["Latitude"]" FloatLabelType="FloatLabelType.Auto" />
</div>
<div class="col-md-4">
<SfNumericTextBox TValue="decimal?" Min=0.0m Max=360.0m Step=0.01m Format="n2" @bind-Value=@location.Longitude Enabled="true" Placeholder="@_lc.Keys["Longitude"]" FloatLabelType="FloatLabelType.Auto" />
</div>
<div class="col-md-4">
<SfNumericTextBox TValue="decimal?" Min="-90.000000m" Max="90.000000m" Step="0.000001m" Format="n6"
@bind-Value=@location.Latitude Enabled="true"
Placeholder="@_lc.Keys["Latitude"]" FloatLabelType="FloatLabelType.Auto" />
</div>
<div class="col-md-4">
<SfNumericTextBox TValue="decimal?" Min="-180.000000m" Max="180.000000m" Step="0.000001m" Format="n6"
@bind-Value=@location.Longitude Enabled="true"
Placeholder="@_lc.Keys["Longitude"]" FloatLabelType="FloatLabelType.Auto" />
</div>
<div class="row">
<div class="col-md-12">
Expand Down Expand Up @@ -136,8 +138,8 @@ else
<GridColumn Field=@nameof(Location.BuildCity) ShowColumnMenu="false" HeaderText="Build City" Type="ColumnType.String" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.BuildState) ShowColumnMenu="false" HeaderText="Build State" Type="ColumnType.String" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.BuildPostalCode) ShowColumnMenu="false" HeaderText="Build Postal Code" Type="ColumnType.String" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.Latitude) ShowColumnMenu="false" HeaderText="Latitude" Type="ColumnType.Number" Format="###.##" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.Longitude) ShowColumnMenu="false" HeaderText="Longitude" Type="ColumnType.Number" Format="###.##" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.Latitude) ShowColumnMenu="false" HeaderText="Latitude" Type="ColumnType.Number" Format="###.######" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridColumn Field=@nameof(Location.Longitude) ShowColumnMenu="false" HeaderText="Longitude" Type="ColumnType.Number" Format="###.######" AllowEditing="false" AllowFiltering="false" AutoFit="true" />
<GridForeignColumn Field=@nameof(Location.MetroAreaId) ForeignDataSource=@MetroAreas ForeignKeyField="MetroAreaId" ForeignKeyValue="Name" ShowColumnMenu="true" HeaderText="Metro Area" Type="ColumnType.String" AllowEditing="false" AllowGrouping="true" AllowFiltering="true" AutoFit="true" />
</GridColumns>
</SfGrid>
Expand Down
2 changes: 1 addition & 1 deletion BedBrigade.Client/Components/LocationGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public partial class LocationGrid : ComponentBase
protected string? Hide { get; private set; } = "true";
public bool NoPaging { get; private set; }

protected DialogSettings DialogParams = new DialogSettings { Width = "800px", MinHeight = "500px", EnableResize = true };
protected DialogSettings DialogParams = new DialogSettings { Width = "800px", MinHeight = "80%", EnableResize = true };

/// <summary>
/// Setup the configuration Grid component
Expand Down
59 changes: 53 additions & 6 deletions BedBrigade.Data/Data/Seeding/Seed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,25 @@ public static class Seed
BuildCity = "Grove City",
BuildState= "OH",
BuildPostalCode= "43123",
IsActive = true
IsActive = true,
Latitude = 39.879740M,
Longitude = -83.042570M

},
new Location
{
Name = "Rock City Polaris Bed Brigade", Route = "/rock-city-polaris",
MailingAddress = "1250 Gemini Pl",
MailingAddress = "171 E. Fifth Ave",
MailingCity = "Columbus",
MailingState = "OH",
MailingPostalCode = "43240",
BuildAddress = "1250 Gemini Pl",
MailingPostalCode = "43201",
BuildAddress = "171 E. Fifth Ave",
BuildCity = "Columbus",
BuildState = "OH",
BuildPostalCode = "43240",
IsActive = true
BuildPostalCode = "43201",
IsActive = true,
Latitude = 39.986740M,
Longitude = -83.000680M
}

};
Expand Down Expand Up @@ -113,6 +118,7 @@ public static async Task SeedData(IDbContextFactory<DataContext> contextFactory)
{
await SeedConfigurations(contextFactory);
await SeedLocations(contextFactory);
await UpdateLocations(contextFactory);
await SeedMetroAreas(contextFactory);
await SeedContentsLogic.SeedContents(contextFactory);
await SeedMedia(contextFactory);
Expand All @@ -128,6 +134,47 @@ public static async Task SeedData(IDbContextFactory<DataContext> contextFactory)
await SeedSpokenLanguages(contextFactory);
}

private static async Task UpdateLocations(IDbContextFactory<DataContext> contextFactory)
{
Log.Logger.Information("UpdateLocations Started");

using (var context = contextFactory.CreateDbContext())
{
var existingLocations =
await context.Locations.Where(o => o.LocationId > Defaults.NationalLocationId && o.Longitude == null).ToListAsync();

if (!existingLocations.Any())
return;

try
{
foreach (var existingLocation in existingLocations)
{
var newData = _locations.First(o => o.Name == existingLocation.Name);
existingLocation.Latitude = newData.Latitude;
existingLocation.Longitude = newData.Longitude;
existingLocation.MailingAddress = newData.MailingAddress;
existingLocation.MailingCity = newData.MailingCity;
existingLocation.MailingState = newData.MailingState;
existingLocation.MailingPostalCode = newData.MailingPostalCode;

existingLocation.BuildAddress = newData.BuildAddress;
existingLocation.BuildCity = newData.BuildCity;
existingLocation.BuildState = newData.BuildState;
existingLocation.BuildPostalCode = newData.BuildPostalCode;

SeedRoutines.SetMaintFields(existingLocation);
context.Locations.Update(existingLocation);
}
await context.SaveChangesAsync();
}
catch (Exception ex)
{
Log.Logger.Information($"Location seed error: {ex.Message}");
throw;
}
}
}
private static async Task SeedSpokenLanguages(IDbContextFactory<DataContext> contextFactory)
{
Log.Logger.Information("SeedSpokenLanguages Started");
Expand Down
8 changes: 6 additions & 2 deletions BedBrigade.Data/Data/Seeding/SeedRoutines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public static void SetMaintFields<T>(List<T> entities) where T : BaseEntity

public static void SetMaintFields<T>(T entity) where T : BaseEntity
{
entity.CreateUser = SeedConstants.SeedUserName;
entity.CreateDate = DateTime.UtcNow;
if (string.IsNullOrEmpty(entity.CreateUser))
{
entity.CreateUser = SeedConstants.SeedUserName;
entity.CreateDate = DateTime.UtcNow;
}

entity.UpdateUser = SeedConstants.SeedUserName;
entity.UpdateDate = DateTime.UtcNow;
entity.MachineName = Environment.MachineName;
Expand Down
Loading