diff --git a/Sources/EFManager/EFManager.csproj b/Sources/EFManager/EFManager.csproj
index d0ace33..9b550c2 100644
--- a/Sources/EFManager/EFManager.csproj
+++ b/Sources/EFManager/EFManager.csproj
@@ -9,6 +9,7 @@
+
diff --git a/Sources/EFManager/ManagerChampion.cs b/Sources/EFManager/ManagerChampion.cs
index 968e29f..6cb1aa7 100644
--- a/Sources/EFManager/ManagerChampion.cs
+++ b/Sources/EFManager/ManagerChampion.cs
@@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Model;
+using EFMapping;
namespace EFManager
{
@@ -15,22 +16,33 @@ namespace EFManager
public async Task AddItem(Champion? item)
{
- if (item == null)
- return null;
-
- await parent.DbContext.Champions.AddAsync(item.toEF());
- await parent.DbContext.SaveChangesAsync();
+ try
+ {
+ await parent.DbContext.Champions.AddAsync(item.toEF(parent.DbContext));
+ parent.DbContext.SaveChangesAsync();
+ }
+ catch (OperationCanceledException){}
+ catch(DbUpdateException){}
return item;
}
public async Task DeleteItem(Champion? item)
{
- if (item == null)
+ try
+ {
+ var toDelete = parent.DbContext.Champions.Find(item.Name);
+ if (toDelete != null)
+ {
+ parent.DbContext.Champions.Remove(item.toEF(parent.DbContext));
+ parent.DbContext.SaveChangesAsync();
+ return true;
+ }
return false;
-
- parent.DbContext.Champions.Remove(item.toEF());
- await parent.DbContext.SaveChangesAsync();
- return true;
+ }
+ catch (DbUpdateException)
+ {
+ return false;
+ }
}
public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)