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.
169 lines
5.8 KiB
169 lines
5.8 KiB
using EFlib;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Model;
|
|
|
|
namespace EFManager
|
|
{
|
|
public class ManagerChampion : IChampionsManager
|
|
{
|
|
public SQLiteContext context = new SQLiteContext();
|
|
|
|
public async Task<Champion?> AddItem(Champion? item)
|
|
{
|
|
if (item == null)
|
|
return null;
|
|
|
|
await context.AddAsync(item.toEF());
|
|
await context.SaveChangesAsync();
|
|
return item;
|
|
}
|
|
|
|
public Task<bool> DeleteItem(Champion? item)
|
|
{
|
|
if (item == null)
|
|
return false;
|
|
|
|
context.Remove(item.toEF());
|
|
await context.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
IQueryable<Champion> query = Champions.Skip(index).Take(count);
|
|
|
|
if (!string.IsNullOrEmpty(orderingPropertyName))
|
|
{
|
|
query = descending ?
|
|
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
|
|
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
|
|
}
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
IQueryable<Champion> query = Champions
|
|
.Where(c => c.Characteristics.ContainsKey(charName))
|
|
.Skip(index)
|
|
.Take(count);
|
|
|
|
if (!string.IsNullOrEmpty(orderingPropertyName))
|
|
{
|
|
query = descending ?
|
|
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
|
|
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
|
|
}
|
|
|
|
return await query.ToListAsync();
|
|
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
IQueryable<Champion> query = Champions
|
|
.Where(c => c.Class == championClass)
|
|
.Skip(index)
|
|
.Take(count);
|
|
|
|
if (!string.IsNullOrEmpty(orderingPropertyName))
|
|
{
|
|
query = descending ?
|
|
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
|
|
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
|
|
}
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
IQueryable<Champion> query = Champions
|
|
.Where(c => c.Name.Contains(substring))
|
|
.Skip(index)
|
|
.Take(count);
|
|
|
|
if (!string.IsNullOrEmpty(orderingPropertyName))
|
|
{
|
|
query = descending ?
|
|
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
|
|
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
|
|
}
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
IQueryable<Champion> query = Champions;
|
|
|
|
if (runePage != null)
|
|
{
|
|
query = query.Where(c => c.RunePageId == runePage.Id);
|
|
}
|
|
|
|
query = query.Skip(index).Take(count);
|
|
|
|
if (!string.IsNullOrEmpty(orderingPropertyName))
|
|
{
|
|
query = descending ?
|
|
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
|
|
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
|
|
}
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<int> GetNbItems()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<int> GetNbItemsByCharacteristic(string charName)
|
|
{
|
|
return await context.Where(c => c.Characteristics.Any(ch => ch.Name == charName)).CountAsync();
|
|
}
|
|
|
|
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 Task<int> GetNbItemsBySkill(string skill)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |