1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00
This commit is contained in:
Yan Maniez 2018-10-14 01:35:31 +02:00
parent 60115e7d95
commit 63a9e8c39d
2 changed files with 27 additions and 9 deletions

View file

@ -365,24 +365,33 @@ namespace AideDeJeu.ViewModels
public class AideDeJeuContext : DbContext public class AideDeJeuContext : DbContext
{ {
public string DatabasePath { get; set; }
public DbSet<Spell> Spells { get; set; } public DbSet<Spell> Spells { get; set; }
public DbSet<Monster> Monsters { get; set; } public DbSet<Monster> Monsters { get; set; }
//private static bool _created = false;
//public AideDeJeuContext()
//{
// if (!_created)
// {
// _created = true;
// Database.EnsureDeleted();
// Database.EnsureCreated();
// }
//}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseSqlite($"Data Source={DatabasePath}"); var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db");
optionsBuilder.UseSqlite($"Data Source=\"{dbPath}\"");
} }
} }
public async Task<Item> GetItemFromDataAsync(string source, string anchor) public async Task<Item> GetItemFromDataAsync(string source, string anchor)
{ {
var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db"); using (var context = new AideDeJeuContext())
using (var context = new AideDeJeuContext() { DatabasePath = dbPath })
{ {
var monsters = await context.Monsters.ToListAsync(); //var monsters = await context.Monsters.ToListAsync();
await context.SaveChangesAsync();
} }
return null; return null;

View file

@ -2,6 +2,7 @@
using AideDeJeu.ViewModels; using AideDeJeu.ViewModels;
using AideDeJeuLib; using AideDeJeuLib;
using Markdig; using Markdig;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -293,8 +294,16 @@ namespace AideDeJeuCmd
Tests.Xamarin.Forms.Mocks.MockForms.Init(); Tests.Xamarin.Forms.Mocks.MockForms.Init();
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3()); SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
DependencyService.Register<INativeAPI, AideDeJeu.Cmd.Version_CMD>(); DependencyService.Register<INativeAPI, AideDeJeu.Cmd.Version_CMD>();
var store = new StoreViewModel(); //var store = new StoreViewModel();
await store.GetItemFromDataAsync("test", "truc"); //await store.GetItemFromDataAsync("test", "truc");
using (var context = new StoreViewModel.AideDeJeuContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var monsters = await context.Monsters.ToListAsync();
}
return; return;
await ReorderSpellsAsync(); await ReorderSpellsAsync();
return; return;