Fixing local repository management of already loaded entities

This commit is contained in:
Zoe Roux 2020-10-21 00:35:14 +02:00
parent cdf5acbbe9
commit 6958745915
2 changed files with 13 additions and 5 deletions

View File

@ -277,22 +277,28 @@ namespace Kyoo.Controllers
Task<T> IRepository<T>.Create(T item)
{
TInternal obj = new TInternal();
Utility.Assign(obj, item);
TInternal obj = item as TInternal ?? new TInternal();
if (!(item is TInternal))
Utility.Assign(obj, item);
return Create(obj).Cast<T>()
.Then(x => item.ID = x.ID);
}
Task<T> IRepository<T>.CreateIfNotExists(T item)
{
TInternal obj = new TInternal();
Utility.Assign(obj, item);
TInternal obj = item as TInternal ?? new TInternal();
if (!(item is TInternal))
Utility.Assign(obj, item);
return CreateIfNotExists(obj).Cast<T>()
.Then(x => item.ID = x.ID);
}
public Task<T> Edit(T edited, bool resetOld)
{
if (edited is TInternal intern)
return Edit(intern, resetOld).Cast<T>();
TInternal obj = new TInternal();
Utility.Assign(obj, edited);
return base.Edit(obj, resetOld).Cast<T>();
@ -302,6 +308,8 @@ namespace Kyoo.Controllers
Task IRepository<T>.Delete(T obj)
{
if (obj is TInternal intern)
return Delete(intern);
TInternal item = new TInternal();
Utility.Assign(item, obj);
return Delete(item);

@ -1 +1 @@
Subproject commit 735a0e6a1a7ae2653de45b47adc823275a46478d
Subproject commit 0f3faa21fad37b2ed39317d58aa3e295fa1c3a41