You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LOLProject/Sources/ManagersEF/EFManager.Runes.cs

74 lines
2.7 KiB

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<Rune?> AddItem(Rune? item)
{
await parent.DbContext.Rune.AddAsync(item.ToEntity());
return item;
}
public async Task<bool> DeleteItem(Rune? item)
{
parent.DbContext.Rune.Remove(item.ToEntity());
return true;
}
public async Task<IEnumerable<Rune?>> 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<IEnumerable<Rune?>> 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<IEnumerable<Rune?>> 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<int> GetNbItems()
{
return parent.DbContext.Rune.Count();
}
public async Task<int> GetNbItemsByFamily(RuneFamily family)
{
return parent.DbContext.Rune.Where(r => r.Family.Equals(family)).Count();
}
public async Task<int> GetNbItemsByName(string substring)
{
return parent.DbContext.Rune.Where(r => r.Name.Contains(substring)).Count();
}
public async Task<Rune?> UpdateItem(Rune? oldItem, Rune? newItem)
{
parent.DbContext.Rune.Remove(oldItem.ToEntity());
parent.DbContext.Rune.Add(newItem.ToEntity());
return newItem;
}
}
}
}