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

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

@ -5,17 +5,21 @@ using Model;
namespace EFManager
{
public partial class ManagerData
{
public class ManagerChampion : IChampionsManager
{
public SQLiteContext context = new SQLiteContext();
private readonly ManagerData parent;
public ManagerChampion(ManagerData parent)
=> this.parent = parent;
public async Task<Champion?> AddItem(Champion? item)
{
if (item == null)
return null;
await context.AddAsync(item.toEF());
await context.SaveChangesAsync();
await parent.DbContext.Champions.AddAsync(item.toEF());
await parent.DbContext.SaveChangesAsync();
return item;
}
@ -24,15 +28,42 @@ namespace EFManager
if (item == null)
return false;
context.Remove(item.toEF());
await context.SaveChangesAsync();
parent.DbContext.Champions.Remove(item.toEF());
await parent.DbContext.SaveChangesAsync();
return true;
}
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
if (orderingPropertyName != null)
{
if (descending)
{
return await Task.FromResult(parent.DbContext.Champions.OrderByDescending(
c => typeof(EFChampion).GetProperty(orderingPropertyName))
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
}
else
{
return await Task.FromResult(parent.DbContext.Champions.OrderBy(
c => typeof(EFChampion).GetProperty(orderingPropertyName))
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
}
}
else
{
return await Task.FromResult(parent.DbContext.Champions
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
}
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -69,9 +100,9 @@ namespace EFManager
throw new NotImplementedException();
}
public Task<int> GetNbItems()
public async Task<int> GetNbItems()
{
throw new NotImplementedException();
return parent.DbContext.Champions.Count();
}
public async Task<int> GetNbItemsByCharacteristic(string charName)
@ -99,14 +130,21 @@ namespace EFManager
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
public async Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
return parent.DbContext.Champions.Where(champ => skill != null && champ.Skills.Any(Skill => Skill.Name.Equals(skill)))
.Count();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
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.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
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
{
private readonly ManagerData parent;
public ManagerSkin(ManagerData parent)
=> this.parent = parent;
public Task<Skin?> AddItem(Skin? item)
{
throw new NotImplementedException();

@ -11,8 +11,37 @@ namespace EFManager
public static class ManagerTranslate
{
// Champion
public static EFChampion toEF(this Champion Champ) => new EFChampion { Name = Champ.Name, Bio = Champ.Bio, Icon = Champ.Icon };
public static Champion toModel(this EFChampion EFChamp) => new Champion(EFChamp.Name);
public static EFChampion toEF(this Champion Champ, SQLiteContext context)
{
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
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
// Rune
// LargeImage
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);
// Rune
// RunePage
}
}

@ -17,8 +17,8 @@ namespace EFlib
public int Value { get; set; }
// Clé étrangère vers l'entité parente
public EFChampion EFChampion { get; set; }
[ForeignKey("EFChampion")]
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