EF : bug dans le truc pour sauvegarder, l'implementation de IChampionManager est tres chiante

master
pasquizzat 2 years ago
parent e39221abf0
commit f8b4b0cf56

@ -24,7 +24,7 @@
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Model2\LibEntityFramework.csproj" />
<ProjectReference Include="..\TrucAuMilieu.csproj" />
<ProjectReference Include="..\TrucAuMilieu\TrucAuMilieu.csproj" />
</ItemGroup>
</Project>

@ -1,26 +1,24 @@
using LibEntityFramework;
using Model;
using TrucAuMilieu;
ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg");
ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg");
Champion c2 = new Champion("joe");
Console.WriteLine("allo?");
using (var context = new ChampionContext())
{
context.Add(c1);
context.SaveChanges();
var dataMgr = new DataBdd();
Console.WriteLine("champion ajouté");
await dataMgr.ChampionsMgr.AddItem(c2);
Console.WriteLine("champion ajouté");
List<ChampionEntity> l = context.Champs.ToList();
List<Champion> list = dataMgr.ChampionsMgr.GetItems(0, 5).Result.ToList();
foreach (var champion in l) { Console.WriteLine(champion.Name); }
}
using (var data = new Data())
{
List<ChampionEntity> l = data.listChampions());
/*
ChampionContext data = new ChampionContext();
foreach (var champion in l) { Console.WriteLine(champion.Name); }
data.Champs.ToList();
List<ChampionEntity> l = data.listChampions();*/
}
foreach (var champion in list) { Console.WriteLine(champion.Name); }

Binary file not shown.

@ -11,6 +11,11 @@ namespace LibEntityFramework
public DbSet<ChampionEntity> Champs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite("DataSource=laBdd.db");
{
if (!options.IsConfigured)
{
options.UseSqlite("DataSource=laBdd.db");
}
}
}
}

@ -0,0 +1,16 @@
using LibEntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public static class ChampionConvert
{
public static ChampionEntity ChampToEf(this Champion c) => new ChampionEntity(c.Name, c.Bio, c.Icon);
public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name);
}
}

@ -1,18 +0,0 @@
using LibEntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public class Data
{
ChampionContext context = new ChampionContext();
List<ChampionEntity> listChampions()
{
return context.Champs.ToList();
}
}
}

@ -0,0 +1,114 @@
using LibEntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public partial class DataBdd
{
public ChampionContext contextCh = new ChampionContext();
public class ChampionsManager : IChampionsManager
{
private readonly DataBdd parent;
public ChampionsManager(DataBdd parent)
=> this.parent = parent;
public async Task<Champion?> AddItem (Champion? item)
{// ya comme une erreur le truc n'est pas save dans la bdd :(
await parent.contextCh.AddAsync(item.ChampToEf);
await parent.contextCh.SaveChangesAsync();
return item; //ou elle est lerreur je vais menerve elle est ou lerreur >:(
}
public Task<bool> DeleteItem(Champion? item)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)/*
=> parent.contextCh..GetItemsWithFilterAndOrdering(
c => true,
index, count,
orderingPropertyName, descending);*/
{// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi :3
List<ChampionEntity> lch = parent.contextCh.Champs.Take(count).Skip(index).ToList();
List<Champion> items = new List<Champion>();
foreach (var c in lch) { items.Add(c.EfToChamp()); }
return items;
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,25 @@
using LibEntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public partial class DataBdd : IDataManager
{
public DataBdd()
{
ChampionsMgr = new ChampionsManager(this);
}
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager? SkinsMgr { get; }
public IRunesManager? RunesMgr { get; }
public IRunePagesManager? RunePagesMgr { get; }
}
}

@ -1,13 +0,0 @@
using LibEntityFramework;
using Model;
namespace TrucAuMilieu
{
static class toEntity
{
public static ChampionEntity ToEntity(this Champion c)
{
return new ChampionEntity(c.Name, c.Bio, c.Icon);
}
}
}
Loading…
Cancel
Save