using EntityFramwork.Factories; using Model; namespace EntityFramwork.Manager { public class ManagerChampion : IChampionsManager { public Task AddItem(Champion? item) { try { using (BDDContext db = new BDDContext()) { db.Champions.Add(item.ChampionModelToEntity()); db.SaveChanges(); } } catch (Exception ex) { return Task.FromResult(null); } return Task.FromResult(item); } public Task DeleteItem(Champion? item) { if(item == null) { return Task.FromResult(false); } using (BDDContext db = new BDDContext()) { EntityChampions ?entityChamp = db.Champions.Where(e => e.Name == item.Name).FirstOrDefault(); if ( entityChamp == null) { return Task.FromResult(false); } db.Champions.Remove(entityChamp); db.SaveChanges(); } return Task.FromResult(true); } public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { IEnumerable items = new List(); using (BDDContext db = new BDDContext()) { if ( descending == false) { items = db.Champions.Skip(index).Take(count).OrderBy(e => e.Name).Select(e => e.EntityChampionToModele()).ToList(); } else { items = db.Champions.Skip(index).Take(count).OrderByDescending(e => e.Name).Select(e => e.EntityChampionToModele()).ToList(); } } return Task.FromResult(items); } public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) { throw new NotImplementedException(); } public Task GetNbItems() { int nb = 0; using (BDDContext db = new BDDContext()) { nb = db.Champions.Count(); } return Task.FromResult(nb); } public Task GetNbItemsByCharacteristic(string charName) { throw new NotImplementedException(); } public Task GetNbItemsByClass(ChampionClass championClass) { throw new NotImplementedException(); } public Task GetNbItemsByName(string substring) { throw new NotImplementedException(); } public Task GetNbItemsByRunePage(RunePage? runePage) { throw new NotImplementedException(); } public Task GetNbItemsBySkill(Skill? skill) { throw new NotImplementedException(); } public Task GetNbItemsBySkill(string skill) { throw new NotImplementedException(); } public Task UpdateItem(Champion? oldItem, Champion? newItem) { throw new NotImplementedException(); } } }