Cleanup and moved a test to proper place

This commit is contained in:
Joseph Milazzo 2021-01-25 18:22:27 -06:00
parent 165757d338
commit c57b77f092
5 changed files with 31 additions and 32 deletions

View file

@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using API.Constants;
using API.Entities;
using API.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace API.Data
{
@ -31,20 +31,21 @@ namespace API.Data
public static async Task SeedSettings(DataContext context)
{
// NOTE: This needs to check if settings already exists before inserting.
// IList<ServerSetting> defaultSettings = new List<ServerSetting>()
// {
// new ServerSetting() {Key = "CacheDirectory", Value = CacheService.CacheDirectory}
// };
//
// await context.ServerSetting.AddRangeAsync(defaultSettings);
// await context.SaveChangesAsync();
// await context.ServerSetting.AddAsync(new ServerSetting
// {
// CacheDirectory = CacheService.CacheDirectory
// });
//
// await context.SaveChangesAsync();
IList<ServerSetting> defaultSettings = new List<ServerSetting>()
{
new() {Key = "CacheDirectory", Value = CacheService.CacheDirectory}
};
var settings = await context.ServerSetting.Select(s => s).ToListAsync();
foreach (var defaultSetting in defaultSettings)
{
var existing = settings.SingleOrDefault(s => s.Key == defaultSetting.Key);
if (existing == null)
{
settings.Add(defaultSetting);
}
}
await context.SaveChangesAsync();
}
}
}