diff --git a/Data/DataAccessContext.cs b/Data/DataAccessContext.cs index 17e3b7b..c8d175b 100644 --- a/Data/DataAccessContext.cs +++ b/Data/DataAccessContext.cs @@ -31,25 +31,4 @@ namespace ProjectGrid.Data return user; } } - - public class UserData - { - public int? Id { get; set; } - public string Name1 { get; set; } - public string Name2 { get; set; } - public string Email { get; set; } - - public UserData() { } - public UserData(UserModel model) - { - Name1 = model.firstName; - Name2 = model.lastName; - Email = model.email; - } - - public UserModel ToModel() - { - return new UserModel { firstName = Name1, lastName = Name2, email = Email }; - } - } } diff --git a/Data/DemoData.cs b/Data/DemoData.cs index 2e287a8..f881a54 100644 --- a/Data/DemoData.cs +++ b/Data/DemoData.cs @@ -4,36 +4,36 @@ using System.Linq; namespace ProjectGrid.Data { - public static class DbInitializer + public static class DbInitializer + { + + public static void Initialize(DataAccessContext context) { + context.Database.EnsureCreated(); - public static void Initialize(DataAccessContext context) - { - context.Database.EnsureCreated(); + // Look for any UserDatas. + if (context.Users.Any()) + { + return; // DB has been seeded + } - // Look for any UserDatas. - if (context.Users.Any()) - { - return; // DB has been seeded - } + /*var users = new UserData[] + { + new UserData{Name1="Carson",Name2="Alexander",Email="test@abc.com"}, + new UserData{Name1="Meredith",Name2="Alonso",Email="test@abc.com"}, + new UserData{Name1="Arturo",Name2="Anand",Email="test@abc.com"}, + new UserData{Name1="Gytis",Name2="Barzdukas",Email="test@abc.com"}, + new UserData{Name1="Yan",Name2="Li",Email="test@abc.com"}, + new UserData{Name1="Peggy",Name2="Justice",Email="test@abc.com"}, + new UserData{Name1="Laura",Name2="Norman",Email="test@abc.com"}, + new UserData{Name1="Nino",Name2="Olivetto",Email="test@abc.com"} + }; + foreach (UserData s in users) + { + context.Users.Add(s); + }*/ + context.SaveChanges(); - var users = new UserData[] - { - new UserData{Name1="Carson",Name2="Alexander",Email="test@abc.com"}, - new UserData{Name1="Meredith",Name2="Alonso",Email="test@abc.com"}, - new UserData{Name1="Arturo",Name2="Anand",Email="test@abc.com"}, - new UserData{Name1="Gytis",Name2="Barzdukas",Email="test@abc.com"}, - new UserData{Name1="Yan",Name2="Li",Email="test@abc.com"}, - new UserData{Name1="Peggy",Name2="Justice",Email="test@abc.com"}, - new UserData{Name1="Laura",Name2="Norman",Email="test@abc.com"}, - new UserData{Name1="Nino",Name2="Olivetto",Email="test@abc.com"} - }; - foreach (UserData s in users) - { - context.Users.Add(s); - } - context.SaveChanges(); - - } } + } } \ No newline at end of file diff --git a/Data/MapData.cs b/Data/MapData.cs new file mode 100644 index 0000000..dbbabe0 --- /dev/null +++ b/Data/MapData.cs @@ -0,0 +1,16 @@ +using ProjectGrid.Models; + + +namespace ProjectGrid.Data +{ + public class MapData + { + public int? Id { get; set; } + + public uint Width { get; set; } + public uint Height { get; set; } + + public MapData() { } + + } +} diff --git a/Data/UserData.cs b/Data/UserData.cs new file mode 100644 index 0000000..fe0485e --- /dev/null +++ b/Data/UserData.cs @@ -0,0 +1,26 @@ +using ProjectGrid.Models; + + +namespace ProjectGrid.Data +{ + public class UserData + { + public int? Id { get; set; } + public string Name1 { get; set; } + public string Name2 { get; set; } + public string Email { get; set; } + + public UserData() { } + public UserData(UserModel model) + { + Name1 = model.firstName; + Name2 = model.lastName; + Email = model.email; + } + + public UserModel ToModel() + { + return new UserModel { firstName = Name1, lastName = Name2, email = Email }; + } + } +} diff --git a/Program.cs b/Program.cs index 6d97594..405facb 100644 --- a/Program.cs +++ b/Program.cs @@ -11,43 +11,43 @@ using Microsoft.Extensions.Logging; namespace ProjectGrid { - public class Program + public class Program + { + + private static ILogger _logger; + public static void Main(string[] args) { + var host = CreateHostBuilder(args).Build(); - private static ILogger _logger; - public static void Main(string[] args) + using (var scope = host.Services.CreateScope()) + { + var services = scope.ServiceProvider; + _logger = services.GetRequiredService>(); + try { - var host = CreateHostBuilder(args).Build(); - - using (var scope = host.Services.CreateScope()) - { - var services = scope.ServiceProvider; - _logger = services.GetRequiredService>(); - try - { - var context = services.GetRequiredService(); - DbInitializer.Initialize(context); - } - catch (Exception ex) - { - - _logger.LogError(ex, "An error occurred while seeding the database."); - } - } - - host.Run(); + var context = services.GetRequiredService(); + DbInitializer.Initialize(context); } + catch (Exception ex) + { - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureLogging(loggingBuilder => - { - loggingBuilder.ClearProviders(); - loggingBuilder.AddDebug().AddConsole(); - }) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + _logger.LogError(ex, "An error occurred while seeding the database."); + } + } + + host.Run(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureLogging(loggingBuilder => + { + loggingBuilder.ClearProviders(); + loggingBuilder.AddDebug().AddConsole(); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } } diff --git a/ProjectGrid.sln b/ProjectGrid.sln new file mode 100644 index 0000000..ba98253 --- /dev/null +++ b/ProjectGrid.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31025.194 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectGrid", "ProjectGrid.csproj", "{C35FFE8E-105A-4EFB-9FA8-E08C0EBDEE71}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C35FFE8E-105A-4EFB-9FA8-E08C0EBDEE71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C35FFE8E-105A-4EFB-9FA8-E08C0EBDEE71}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C35FFE8E-105A-4EFB-9FA8-E08C0EBDEE71}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C35FFE8E-105A-4EFB-9FA8-E08C0EBDEE71}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C1D55053-1465-4925-B898-8867FB608551} + EndGlobalSection +EndGlobal