Compare commits
No commits in common. "5701c9e43eac43b891170d0b71d2fdb35923d3fe" and "4b220c97e49d8c3f9a21581e18999c0e8c66fb5a" have entirely different histories.
5701c9e43e
...
4b220c97e4
|
|
@ -31,4 +31,25 @@ namespace ProjectGrid.Data
|
||||||
return user;
|
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 };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,36 @@ using System.Linq;
|
||||||
|
|
||||||
namespace ProjectGrid.Data
|
namespace ProjectGrid.Data
|
||||||
{
|
{
|
||||||
public static class DbInitializer
|
public static class DbInitializer
|
||||||
{
|
|
||||||
|
|
||||||
public static void Initialize(DataAccessContext context)
|
|
||||||
{
|
{
|
||||||
context.Database.EnsureCreated();
|
|
||||||
|
|
||||||
// Look for any UserDatas.
|
public static void Initialize(DataAccessContext context)
|
||||||
if (context.Users.Any())
|
{
|
||||||
{
|
context.Database.EnsureCreated();
|
||||||
return; // DB has been seeded
|
|
||||||
}
|
|
||||||
|
|
||||||
/*var users = new UserData[]
|
// Look for any UserDatas.
|
||||||
{
|
if (context.Users.Any())
|
||||||
new UserData{Name1="Carson",Name2="Alexander",Email="test@abc.com"},
|
{
|
||||||
new UserData{Name1="Meredith",Name2="Alonso",Email="test@abc.com"},
|
return; // DB has been seeded
|
||||||
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();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
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() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
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 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
66
Program.cs
66
Program.cs
|
|
@ -11,43 +11,43 @@ using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace ProjectGrid
|
namespace ProjectGrid
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
|
||||||
|
|
||||||
private static ILogger _logger;
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
var host = CreateHostBuilder(args).Build();
|
|
||||||
|
|
||||||
using (var scope = host.Services.CreateScope())
|
private static ILogger _logger;
|
||||||
{
|
public static void Main(string[] args)
|
||||||
var services = scope.ServiceProvider;
|
|
||||||
_logger = services.GetRequiredService<ILogger<Program>>();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var context = services.GetRequiredService<DataAccessContext>();
|
|
||||||
DbInitializer.Initialize(context);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
|
var host = CreateHostBuilder(args).Build();
|
||||||
|
|
||||||
_logger.LogError(ex, "An error occurred while seeding the database.");
|
using (var scope = host.Services.CreateScope())
|
||||||
}
|
{
|
||||||
}
|
var services = scope.ServiceProvider;
|
||||||
|
_logger = services.GetRequiredService<ILogger<Program>>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var context = services.GetRequiredService<DataAccessContext>();
|
||||||
|
DbInitializer.Initialize(context);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
host.Run();
|
_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<Startup>();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
||||||
Host.CreateDefaultBuilder(args)
|
|
||||||
.ConfigureLogging(loggingBuilder =>
|
|
||||||
{
|
|
||||||
loggingBuilder.ClearProviders();
|
|
||||||
loggingBuilder.AddDebug().AddConsole();
|
|
||||||
})
|
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
|
||||||
{
|
|
||||||
webBuilder.UseStartup<Startup>();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
|
|
||||||
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
|
|
||||||
Loading…
Reference in New Issue