2020-12-02 23:05:06 +01:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-01-02 17:34:45 +01:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2020-12-02 23:05:06 +01:00
|
|
|
|
using SessionCompanion.Database.Tables;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-01-02 17:34:45 +01:00
|
|
|
|
using System.IO;
|
2020-12-02 23:05:06 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SessionCompanion.Database
|
|
|
|
|
{
|
|
|
|
|
public class ApplicationDbContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
public virtual DbSet<Alignment> Alignments { get; set; }
|
|
|
|
|
public virtual DbSet<Background> Backgrounds { get; set; }
|
|
|
|
|
public virtual DbSet<Biography> Biographies { get; set; }
|
|
|
|
|
public virtual DbSet<Character> Characters { get; set; }
|
2020-12-04 15:49:51 +01:00
|
|
|
|
public virtual DbSet<Charisma> Charismas { get; set; }
|
2020-12-02 23:05:06 +01:00
|
|
|
|
public virtual DbSet<Class> Classes { get; set; }
|
2020-12-04 15:49:51 +01:00
|
|
|
|
public virtual DbSet<Constitution> Constitutions { get; set; }
|
|
|
|
|
public virtual DbSet<Dexterity> Dexterities { get; set; }
|
|
|
|
|
public virtual DbSet<Intelligence> Intelligences { get; set; }
|
2020-12-02 23:05:06 +01:00
|
|
|
|
public virtual DbSet<Race> Races { get; set; }
|
|
|
|
|
public virtual DbSet<Statistics> Statistics { get; set; }
|
2020-12-04 15:49:51 +01:00
|
|
|
|
public virtual DbSet<Strength> Strengths { get; set; }
|
2020-12-02 23:05:06 +01:00
|
|
|
|
public virtual DbSet<User> Users { get; set; }
|
2020-12-04 15:49:51 +01:00
|
|
|
|
public virtual DbSet<Wisdom> Wisdoms { get; set; }
|
2020-12-27 20:08:19 +01:00
|
|
|
|
public virtual DbSet<Spell> Spells { get; set; }
|
|
|
|
|
public virtual DbSet<CharacterSpell> CharacterSpells { get; set; }
|
|
|
|
|
public virtual DbSet<CharacterSpellSlots> CharacterSpellSlots { get; set; }
|
2020-12-27 19:47:13 +01:00
|
|
|
|
public virtual DbSet<Armor> Armors { get; set; }
|
|
|
|
|
public virtual DbSet<CharacterArmor> CharacterArmors { get; set; }
|
|
|
|
|
public virtual DbSet<Weapon> Weapons { get; set; }
|
|
|
|
|
public virtual DbSet<CharacterWeapon> CharacterWeapons { get; set; }
|
|
|
|
|
public virtual DbSet<OtherEquipment> OtherEquipment { get; set; }
|
|
|
|
|
public virtual DbSet<CharacterOtherEquipment> CharacterOtherEquipment { get; set; }
|
2020-12-02 23:05:06 +01:00
|
|
|
|
|
|
|
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
|
|
|
|
|
|
2021-01-02 17:34:45 +01:00
|
|
|
|
protected IEnumerable<Weapon> SeedWeapon()
|
|
|
|
|
{
|
|
|
|
|
const string file = "../SessionCompanion.Database/JsonData/weapons.json";
|
|
|
|
|
List<Weapon> weapons = new List<Weapon>();
|
|
|
|
|
using (StreamReader reader = new StreamReader(file))
|
|
|
|
|
{
|
|
|
|
|
var json = reader.ReadToEnd();
|
|
|
|
|
dynamic jweapons = JArray.Parse(json);
|
|
|
|
|
foreach (dynamic item in jweapons)
|
|
|
|
|
weapons.Add(SeedFromJsons.SingleWeaponSeeder(item));
|
|
|
|
|
}
|
|
|
|
|
return weapons;
|
|
|
|
|
}
|
|
|
|
|
protected IEnumerable<Armor> SeedArmor()
|
|
|
|
|
{
|
|
|
|
|
const string file = "../SessionCompanion.Database/JsonData/armors.json";
|
|
|
|
|
List<Armor> armors = new List<Armor>();
|
|
|
|
|
using (StreamReader reader = new StreamReader(file))
|
|
|
|
|
{
|
|
|
|
|
var json = reader.ReadToEnd();
|
|
|
|
|
dynamic jactions = JArray.Parse(json);
|
|
|
|
|
int id = 1;
|
|
|
|
|
foreach (dynamic item in jactions)
|
|
|
|
|
{
|
|
|
|
|
armors.Add(SeedFromJsons.SingleArmorSeeder(item, id));
|
|
|
|
|
id++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return armors;
|
|
|
|
|
}
|
|
|
|
|
protected IEnumerable<OtherEquipment> SeedOtherEquipment()
|
|
|
|
|
{
|
|
|
|
|
const string file = "../SessionCompanion.Database/JsonData/otherEquipments.json";
|
|
|
|
|
List<OtherEquipment> otherEquipment = new List<OtherEquipment>();
|
|
|
|
|
using (StreamReader reader = new StreamReader(file))
|
|
|
|
|
{
|
|
|
|
|
var json = reader.ReadToEnd();
|
|
|
|
|
dynamic jactions = JArray.Parse(json);
|
|
|
|
|
int id = 1;
|
|
|
|
|
foreach (dynamic item in jactions)
|
|
|
|
|
{
|
|
|
|
|
otherEquipment.Add(SeedFromJsons.SingleOtherEquipmentSeeder(item, id));
|
|
|
|
|
id++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return otherEquipment;
|
|
|
|
|
}
|
2020-12-03 17:00:04 +01:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.OnModelCreating(builder);
|
2020-12-03 17:50:11 +01:00
|
|
|
|
builder.Entity<User>().HasData(SeedData.SeedUsers());
|
2020-12-18 12:00:36 +01:00
|
|
|
|
builder.Entity<Character>().HasData(SeedData.SeedCharacter());
|
|
|
|
|
builder.Entity<Race>().HasData(SeedData.SeedRace());
|
|
|
|
|
builder.Entity<Class>().HasData(SeedData.SeedClass());
|
|
|
|
|
builder.Entity<Alignment>().HasData(SeedData.SeedAlignment());
|
|
|
|
|
builder.Entity<Background>().HasData(SeedData.SeedBackground());
|
|
|
|
|
builder.Entity<Biography>().HasData(SeedData.SeedBiography());
|
|
|
|
|
builder.Entity<Statistics>().HasData(SeedData.SeedStatistics());
|
2021-01-02 17:34:45 +01:00
|
|
|
|
builder.Entity<Weapon>().HasData(SeedWeapon());
|
|
|
|
|
builder.Entity<Armor>().HasData(SeedArmor());
|
|
|
|
|
builder.Entity<OtherEquipment>().HasData(SeedOtherEquipment());
|
|
|
|
|
builder.Entity<CharacterWeapon>().HasData(SeedData.SeedCharacterWeapon());
|
|
|
|
|
builder.Entity<CharacterArmor>().HasData(SeedData.SeedCharacterArmor());
|
|
|
|
|
builder.Entity<CharacterOtherEquipment>().HasData(SeedData.SeedCharacterOtherEquipment());
|
2021-01-04 00:59:23 +01:00
|
|
|
|
builder.Entity<Charisma>().HasData(SeedData.SeedCharisma());
|
|
|
|
|
builder.Entity<Constitution>().HasData(SeedData.SeedConstitution());
|
|
|
|
|
builder.Entity<Dexterity>().HasData(SeedData.SeedDexterity());
|
|
|
|
|
builder.Entity<Intelligence>().HasData(SeedData.SeedIntelligence());
|
|
|
|
|
builder.Entity<Strength>().HasData(SeedData.SeedStrength());
|
|
|
|
|
builder.Entity<Wisdom>().HasData(SeedData.SeedWisdom());
|
|
|
|
|
|
2020-12-03 17:00:04 +01:00
|
|
|
|
}
|
2020-12-02 23:05:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|