|
|
@ -17,13 +17,8 @@ namespace Business
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Champion?> AddItem(Champion? item)
|
|
|
|
public async Task<Champion?> AddItem(Champion? item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
await parent.DbContext.champions.AddAsync(item.ToEntity(parent.DbContext));
|
|
|
|
{
|
|
|
|
parent.DbContext.SaveChanges();
|
|
|
|
await parent.DbContext.champions.AddAsync(item.ToEntity(parent.DbContext));
|
|
|
|
|
|
|
|
parent.DbContext.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(OperationCanceledException){}
|
|
|
|
|
|
|
|
catch(DbUpdateException) {}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -40,16 +35,12 @@ namespace Business
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (DbUpdateException)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async 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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine("GET");
|
|
|
|
Console.WriteLine("GET");
|
|
|
|
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
c => true,
|
|
|
|
c => true,
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -58,7 +49,7 @@ namespace Business
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return parent.DbContext.champions.Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
c => c.Characteristics.Any(ch => ch.Name.Equals(charName)),
|
|
|
|
c => c.Characteristics.Any(ch => ch.Name.Equals(charName)),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -66,7 +57,7 @@ namespace Business
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
c => c.Class.Equals(championClass),
|
|
|
|
c => c.Class.Equals(championClass),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -74,7 +65,7 @@ namespace Business
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
c => c.Name.Contains(substring),
|
|
|
|
c => c.Name.Contains(substring),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -83,7 +74,7 @@ namespace Business
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return parent.DbContext.champions.Include("runepages").GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").Include("runepages").GetItemsWithFilterAndOrdering(
|
|
|
|
c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity(parent.DbContext))),
|
|
|
|
c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity(parent.DbContext))),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -92,7 +83,7 @@ namespace Business
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
|
|
|
|
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)),
|
|
|
|
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -100,7 +91,7 @@ namespace Business
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return parent.DbContext.champions.Include("Skills").GetItemsWithFilterAndOrdering(
|
|
|
|
return parent.DbContext.champions.Include("Skills").Include("Characteristics").Include("Skills").GetItemsWithFilterAndOrdering(
|
|
|
|
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)),
|
|
|
|
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)),
|
|
|
|
index, count,
|
|
|
|
index, count,
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
|
orderingPropertyName, descending).Select(c => c.ToModel());
|
|
|
@ -149,12 +140,8 @@ namespace Business
|
|
|
|
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
|
|
|
|
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var toUpdate = parent.DbContext.champions.Find(oldItem.Name);
|
|
|
|
var toUpdate = parent.DbContext.champions.Find(oldItem.Name);
|
|
|
|
try
|
|
|
|
toUpdate = newItem.ToEntity(parent.DbContext);
|
|
|
|
{
|
|
|
|
parent.DbContext.SaveChanges();
|
|
|
|
toUpdate = newItem.ToEntity(parent.DbContext);
|
|
|
|
|
|
|
|
parent.DbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (DbUpdateException){}
|
|
|
|
|
|
|
|
return newItem;
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|