|
|
@ -2,6 +2,7 @@
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
using EFMapping;
|
|
|
|
|
|
|
|
|
|
|
|
namespace EFManager
|
|
|
|
namespace EFManager
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -15,23 +16,34 @@ namespace EFManager
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Champion?> AddItem(Champion? item)
|
|
|
|
public async Task<Champion?> AddItem(Champion? item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (item == null)
|
|
|
|
try
|
|
|
|
return null;
|
|
|
|
{
|
|
|
|
|
|
|
|
await parent.DbContext.Champions.AddAsync(item.toEF(parent.DbContext));
|
|
|
|
await parent.DbContext.Champions.AddAsync(item.toEF());
|
|
|
|
parent.DbContext.SaveChangesAsync();
|
|
|
|
await parent.DbContext.SaveChangesAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (OperationCanceledException){}
|
|
|
|
|
|
|
|
catch(DbUpdateException){}
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DeleteItem(Champion? item)
|
|
|
|
public async Task<bool> DeleteItem(Champion? item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (item == null)
|
|
|
|
try
|
|
|
|
return false;
|
|
|
|
{
|
|
|
|
|
|
|
|
var toDelete = parent.DbContext.Champions.Find(item.Name);
|
|
|
|
parent.DbContext.Champions.Remove(item.toEF());
|
|
|
|
if (toDelete != null)
|
|
|
|
await parent.DbContext.SaveChangesAsync();
|
|
|
|
{
|
|
|
|
|
|
|
|
parent.DbContext.Champions.Remove(item.toEF(parent.DbContext));
|
|
|
|
|
|
|
|
parent.DbContext.SaveChangesAsync();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|