sjdhfkjsdfkjsdhf
<my-header />
dskflhsldfjlsd
<my-sidebar />
fkjslfjdsf
<my-footer />
...
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "MyWebProject")
.AddJsonFile("appsettings.json", false)
.AddJsonFile("appsettings.Development.json", true)
.Build();
IHostBuilder builder = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder =>
{
builder.Sources.Clear();
builder.AddConfiguration(configuration);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
IHost host = builder.Build();
Console.WriteLine(host);
var dbContext = (ApplicationDbContext)host.Services.GetService(typeof(ApplicationDbContext));
var userIds = new List<int>{1, 2};
var userProfiles = dbContext.UserProfiles
.Where(up => userIds.Contains(up.Id))
.ToList();
Console.WriteLine(userProfiles.Count);
...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MyWebProject.Data;
namespace MyWebProjectCLI
{
class Program
{
static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(string[] args) {
Console.WriteLine("Hello World!");
Console.WriteLine(Directory.GetCurrentDirectory());
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "MyWebProject")
.AddJsonFile("appsettings.json", false)
.AddJsonFile("appsettings.Development.json", true)
.Build();
var _connectionString = configuration.GetConnectionString("DefaultConnection");
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseNpgsql(_connectionString)
.UseSnakeCaseNamingConvention().Options;
using (var dbContext = new ApplicationDbContext(options))
{
Console.WriteLine("Doom");
var userStore = new UserStore<ApplicationUser>(dbContext);
UserManager<ApplicationUser> _userManager = new UserManager<ApplicationUser>(userStore, null, new PasswordHasher<ApplicationUser>(), null, null, null, null, null, null);
var userIds = new List<int>{1, 2};
var userProfiles = dbContext.UserProfiles
.Where(up => userIds.Contains(up.Id))
.ToList();
Console.WriteLine(userProfiles.Count);
foreach (var up in userProfiles)
{
Console.WriteLine(JsonSerializer.Serialize(up));
var oldData = up.OldData.RootElement;
var user = new ApplicationUser { UserName = oldData.GetProperty("username").ToString(),
Email = oldData.GetProperty("email").ToString() };
var result = await _userManager.CreateAsync(user, oldData.GetProperty("encrypted_password").ToString());
if (!result.Succeeded)
{
Console.WriteLine("ERROR");
break;
}
}
}
}
}
}