using APILOL.Mapper; using Model; using Shared; namespace ManagersEF { public partial class EFManager { public class RunesManager : IRunesManager { private readonly EFManager parent; public RunesManager(EFManager parent) => this.parent = parent; public async Task AddItem(Rune? item) { await parent.DbContext.Rune.AddAsync(item.ToEntity()); return item; } public async Task DeleteItem(Rune? item) { parent.DbContext.Rune.Remove(item.ToEntity()); return true; } public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { return parent.DbContext.Rune.GetItemsWithFilterAndOrdering( r => true, index, count, orderingPropertyName, descending).Select(r => r.ToModel()); } public async Task> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false) { return parent.DbContext.Rune.GetItemsWithFilterAndOrdering( r => r.Family.Equals(family), index, count, orderingPropertyName, descending).Select(r => r.ToModel()); } public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { return parent.DbContext.Rune.GetItemsWithFilterAndOrdering( r => r.Name.Contains(substring), index, count, orderingPropertyName, descending).Select(r => r.ToModel()); } public async Task GetNbItems() { return parent.DbContext.Rune.Count(); } public async Task GetNbItemsByFamily(RuneFamily family) { return parent.DbContext.Rune.Where(r => r.Family.Equals(family)).Count(); } public async Task GetNbItemsByName(string substring) { return parent.DbContext.Rune.Where(r => r.Name.Contains(substring)).Count(); } public async Task UpdateItem(Rune? oldItem, Rune? newItem) { parent.DbContext.Rune.Remove(oldItem.ToEntity()); parent.DbContext.Rune.Add(newItem.ToEntity()); return newItem; } } } }