mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
b703899912
commit
d726bd0a0e
4 changed files with 2 additions and 60 deletions
|
|
@ -1,8 +1,5 @@
|
|||
using FilterLists.Data;
|
||||
using FilterLists.Data.Contexts;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FilterLists.Api
|
||||
{
|
||||
|
|
@ -10,12 +7,7 @@ public class Program
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = BuildWebHost(args);
|
||||
//using (var scope = host.Services.CreateScope())
|
||||
//{
|
||||
// DbInitializer.Initialize(scope.ServiceProvider.GetRequiredService<FilterListsDbContext>());
|
||||
//}
|
||||
host.Run();
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args)
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
using FilterLists.Data.Contexts;
|
||||
using FilterLists.Data.Models;
|
||||
using FilterLists.Data.Repositories.Implementations;
|
||||
|
||||
namespace FilterLists.Data
|
||||
{
|
||||
public static class DbInitializer
|
||||
{
|
||||
public static void Initialize(FilterListsDbContext filterListsDbContext)
|
||||
{
|
||||
filterListsDbContext.Database.EnsureCreated();
|
||||
InitializeList(filterListsDbContext);
|
||||
}
|
||||
|
||||
private static void InitializeList(FilterListsDbContext filterListsDbContext)
|
||||
{
|
||||
var listRepository = new ListRepository(filterListsDbContext);
|
||||
if (listRepository.Any())
|
||||
{
|
||||
listRepository.DeleteAll();
|
||||
}
|
||||
var lists = new List[]
|
||||
{
|
||||
//TODO: populate from csv or json
|
||||
};
|
||||
foreach (var list in lists)
|
||||
{
|
||||
listRepository.Create(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,5 @@ public interface IListRepository
|
|||
{
|
||||
IEnumerable<List> GetAll();
|
||||
List GetByName(string listName);
|
||||
void Create(List list);
|
||||
void DeleteAll();
|
||||
bool Any();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,20 +24,5 @@ public List GetByName(string listName)
|
|||
{
|
||||
return _filterListsDbContext.List.First(x => x.Name == listName);
|
||||
}
|
||||
|
||||
public void Create(List list)
|
||||
{
|
||||
_filterListsDbContext.List.Add(list);
|
||||
}
|
||||
|
||||
public void DeleteAll()
|
||||
{
|
||||
_filterListsDbContext.List.RemoveRange(_filterListsDbContext.List);
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return _filterListsDbContext.List.Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue