Compare commits
2 Commits
4b220c97e4
...
5701c9e43e
| Author | SHA1 | Date |
|---|---|---|
|
|
5701c9e43e | |
|
|
d81bb5c351 |
|
|
@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
66
Program.cs
66
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<ILogger<Program>>();
|
||||
try
|
||||
{
|
||||
var host = CreateHostBuilder(args).Build();
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
_logger.LogError(ex, "An error occurred while seeding the database.");
|
||||
}
|
||||
}
|
||||
|
||||
host.Run();
|
||||
var context = services.GetRequiredService<DataAccessContext>();
|
||||
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<Startup>();
|
||||
});
|
||||
_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>();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue