Update EF
continuous-integration/drone/push Build is failing Details

master
Louis DUFOUR 2 years ago
parent 4bfb1d33bb
commit 6ed47df635

@ -5,108 +5,146 @@ using Model;
namespace EFManager namespace EFManager
{ {
public class ManagerChampion : IChampionsManager public partial class ManagerData
{ {
public SQLiteContext context = new SQLiteContext(); public class ManagerChampion : IChampionsManager
{
public async Task<Champion?> AddItem(Champion? item) private readonly ManagerData parent;
{ public ManagerChampion(ManagerData parent)
if (item == null) => this.parent = parent;
return null;
public async Task<Champion?> AddItem(Champion? item)
await context.AddAsync(item.toEF()); {
await context.SaveChangesAsync(); if (item == null)
return item; return null;
}
await parent.DbContext.Champions.AddAsync(item.toEF());
public async Task<bool> DeleteItem(Champion? item) await parent.DbContext.SaveChangesAsync();
{ return item;
if (item == null) }
return false;
public async Task<bool> DeleteItem(Champion? item)
context.Remove(item.toEF()); {
await context.SaveChangesAsync(); if (item == null)
return true; return false;
}
parent.DbContext.Champions.Remove(item.toEF());
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) await parent.DbContext.SaveChangesAsync();
{ return true;
throw new NotImplementedException(); }
} public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) if (orderingPropertyName != null)
{ {
throw new NotImplementedException(); if (descending)
{
} return await Task.FromResult(parent.DbContext.Champions.OrderByDescending(
c => typeof(EFChampion).GetProperty(orderingPropertyName))
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) .Skip(index * count)
{ .Take(count)
throw new NotImplementedException(); .Select(ce => ce.toModel())
);
} }
else
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) {
{ return await Task.FromResult(parent.DbContext.Champions.OrderBy(
throw new NotImplementedException(); c => typeof(EFChampion).GetProperty(orderingPropertyName))
.Skip(index * count)
} .Take(count)
.Select(ce => ce.toModel())
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) );
{ }
throw new NotImplementedException(); }
else
} {
return await Task.FromResult(parent.DbContext.Champions
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) .Skip(index * count)
{ .Take(count)
throw new NotImplementedException(); .Select(ce => ce.toModel())
} );
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) }
{
throw new NotImplementedException(); public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
} {
throw new NotImplementedException();
public Task<int> GetNbItems()
{ }
throw new NotImplementedException();
} public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
public async Task<int> GetNbItemsByCharacteristic(string charName) throw new NotImplementedException();
{
throw new NotImplementedException(); }
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
public Task<int> GetNbItemsByClass(ChampionClass championClass) {
{ throw new NotImplementedException();
throw new NotImplementedException();
} }
public Task<int> GetNbItemsByName(string substring) public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{ public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
throw new NotImplementedException(); {
} throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{ public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
throw new NotImplementedException(); {
} throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{ public async Task<int> GetNbItems()
throw new NotImplementedException(); {
} return parent.DbContext.Champions.Count();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{ public async Task<int> GetNbItemsByCharacteristic(string charName)
throw new NotImplementedException(); {
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 async Task<int> GetNbItemsBySkill(string skill)
{
return parent.DbContext.Champions.Where(champ => skill != null && champ.Skills.Any(Skill => Skill.Name.Equals(skill)))
.Count();
}
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
var toUpdate = parent.DbContext.Champions.Find(oldItem.Name);
toUpdate = newItem.toEF();
parent.DbContext.SaveChanges();
return newItem;
}
} }
} }
} }

@ -5,21 +5,26 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace EFManager namespace EFManager
{ {
public class ManagerData : IDataManager public partial class ManagerData : IDataManager
{ {
public ManagerData() public ManagerData(SQLiteContext ContextData)
{ {
//ChampionMgr = new ChampionManager(this); TO DO DbContext = ContextData;
ChampionsMgr = new ManagerChampion(this);
SkinsMgr = new ManagerSkin(this);
} }
public IChampionsManager ChampionsMgr { get; set; } protected SQLiteContext DbContext { get; }
public ISkinsManager SkinsMgr { get; set; } public IChampionsManager ChampionsMgr { get; }
public IRunesManager RunesMgr { get; set; } public ISkinsManager SkinsMgr { get; }
public IRunePagesManager RunePagesMgr { get; set; } public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
} }
} }

@ -9,6 +9,9 @@ namespace EFManager
{ {
public class ManagerSkin : ISkinsManager public class ManagerSkin : ISkinsManager
{ {
private readonly ManagerData parent;
public ManagerSkin(ManagerData parent)
=> this.parent = parent;
public Task<Skin?> AddItem(Skin? item) public Task<Skin?> AddItem(Skin? item)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

@ -11,8 +11,37 @@ namespace EFManager
public static class ManagerTranslate public static class ManagerTranslate
{ {
// Champion // Champion
public static EFChampion toEF(this Champion Champ) => new EFChampion { Name = Champ.Name, Bio = Champ.Bio, Icon = Champ.Icon }; public static EFChampion toEF(this Champion Champ, SQLiteContext context)
public static Champion toModel(this EFChampion EFChamp) => new Champion(EFChamp.Name); {
EFChampion? EfChampion = context.Champions.Find(Champ.Name);
if (EfChampion == null)
{
EfChampion = new()
{
Name = Champ.Name,
Bio = Champ.Bio,
Icon = Champ.Icon,
Class = Champ.Class,
Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 },
};
EfChampion.Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList();
EfChampion.Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList();
}
return EfChampion;
}
public static Champion toModel(this EFChampion EFChamp)
{
var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio);
if (EFChamp.Skills != null) foreach (var s in EFChamp.Skills) { champion.AddSkill(s.toModel()); }
if (EFChamp.Characteristics != null) foreach (var c in EFChamp.Characteristics) { champion.AddCharacteristics(c.toModel()); }
return champion;
}
// Characteristics
// Skin // Skin
public static EFSkin toEF(this Skin Skin) => new EFSkin { Name = Skin.Name, Description = Skin.Description, Icon = Skin.Icon, Price = Skin.Price }; public static EFSkin toEF(this Skin Skin) => new EFSkin { Name = Skin.Name, Description = Skin.Description, Icon = Skin.Icon, Price = Skin.Price };
@ -20,12 +49,13 @@ namespace EFManager
// Skill // Skill
// Rune
// LargeImage // LargeImage
public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 }; public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 };
public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64); public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64);
// Rune
// RunePage
} }
} }

@ -17,8 +17,8 @@ namespace EFlib
public int Value { get; set; } public int Value { get; set; }
// Clé étrangère vers l'entité parente // Clé étrangère vers l'entité parente
public EFChampion EFChampion { get; set; }
[ForeignKey("EFChampion")] [ForeignKey("EFChampion")]
public string EFChampionName { get; set; } public string EFChampionName { get; set; }
public EFChampion EFChampion { get; set; }
} }
} }

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestAPI
{
public class UnitTestSkinController
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestEF
{
public class UnitTestSkin
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManagerEF
{
public class UnitTestManagerSkin
{
}
}
Loading…
Cancel
Save