From 8d62c5c0cfdea6a3513ea4f7eba9623956f900b7 Mon Sep 17 00:00:00 2001 From: Greg Finzer Date: Fri, 15 Nov 2024 14:08:26 -0500 Subject: [PATCH] Seed latitude and longitude for Grove City and Rock City Polaris. Ability to edit up to six digits with negative numbers. --- .../Components/LocationGrid.razor | 20 ++++--- .../Components/LocationGrid.razor.cs | 2 +- BedBrigade.Data/Data/Seeding/Seed.cs | 59 +++++++++++++++++-- BedBrigade.Data/Data/Seeding/SeedRoutines.cs | 8 ++- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/BedBrigade.Client/Components/LocationGrid.razor b/BedBrigade.Client/Components/LocationGrid.razor index e22aa0af..10d261ef 100644 --- a/BedBrigade.Client/Components/LocationGrid.razor +++ b/BedBrigade.Client/Components/LocationGrid.razor @@ -99,13 +99,15 @@ else -
-
- -
-
- -
+
+ +
+
+
@@ -136,8 +138,8 @@ else - - + + diff --git a/BedBrigade.Client/Components/LocationGrid.razor.cs b/BedBrigade.Client/Components/LocationGrid.razor.cs index 1f024d2f..9e5eb93c 100644 --- a/BedBrigade.Client/Components/LocationGrid.razor.cs +++ b/BedBrigade.Client/Components/LocationGrid.razor.cs @@ -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 }; /// /// Setup the configuration Grid component diff --git a/BedBrigade.Data/Data/Seeding/Seed.cs b/BedBrigade.Data/Data/Seeding/Seed.cs index 16aad250..ab5b6257 100644 --- a/BedBrigade.Data/Data/Seeding/Seed.cs +++ b/BedBrigade.Data/Data/Seeding/Seed.cs @@ -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 } }; @@ -113,6 +118,7 @@ public static async Task SeedData(IDbContextFactory contextFactory) { await SeedConfigurations(contextFactory); await SeedLocations(contextFactory); + await UpdateLocations(contextFactory); await SeedMetroAreas(contextFactory); await SeedContentsLogic.SeedContents(contextFactory); await SeedMedia(contextFactory); @@ -128,6 +134,47 @@ public static async Task SeedData(IDbContextFactory contextFactory) await SeedSpokenLanguages(contextFactory); } + private static async Task UpdateLocations(IDbContextFactory 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 contextFactory) { Log.Logger.Information("SeedSpokenLanguages Started"); diff --git a/BedBrigade.Data/Data/Seeding/SeedRoutines.cs b/BedBrigade.Data/Data/Seeding/SeedRoutines.cs index 9e41bb2a..d0d03ff8 100644 --- a/BedBrigade.Data/Data/Seeding/SeedRoutines.cs +++ b/BedBrigade.Data/Data/Seeding/SeedRoutines.cs @@ -32,8 +32,12 @@ public static void SetMaintFields(List entities) where T : BaseEntity public static void SetMaintFields(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;