mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Prevent AddedDate edits
This commit is contained in:
parent
4688868f04
commit
274d2987d2
@ -297,6 +297,8 @@ public abstract class GenericRepository<T>(DatabaseContext database) : IReposito
|
|||||||
{
|
{
|
||||||
await Validate(edited);
|
await Validate(edited);
|
||||||
Database.Update(edited);
|
Database.Update(edited);
|
||||||
|
if (edited is IAddedDate date)
|
||||||
|
Database.Entry(date).Property(p => p.AddedDate).IsModified = false;
|
||||||
await Database.SaveChangesAsync();
|
await Database.SaveChangesAsync();
|
||||||
await IRepository<T>.OnResourceEdited(edited);
|
await IRepository<T>.OnResourceEdited(edited);
|
||||||
return edited;
|
return edited;
|
||||||
@ -305,23 +307,15 @@ public abstract class GenericRepository<T>(DatabaseContext database) : IReposito
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual async Task<T> Patch(Guid id, Func<T, T> patch)
|
public virtual async Task<T> Patch(Guid id, Func<T, T> patch)
|
||||||
{
|
{
|
||||||
bool lazyLoading = Database.ChangeTracker.LazyLoadingEnabled;
|
T resource = await GetWithTracking(id);
|
||||||
Database.ChangeTracker.LazyLoadingEnabled = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
T resource = await GetWithTracking(id);
|
|
||||||
|
|
||||||
resource = patch(resource);
|
resource = patch(resource);
|
||||||
|
if (resource is IAddedDate date)
|
||||||
|
Database.Entry(date).Property(p => p.AddedDate).IsModified = false;
|
||||||
|
|
||||||
await Database.SaveChangesAsync();
|
await Database.SaveChangesAsync();
|
||||||
await IRepository<T>.OnResourceEdited(resource);
|
await IRepository<T>.OnResourceEdited(resource);
|
||||||
return resource;
|
return resource;
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Database.ChangeTracker.LazyLoadingEnabled = lazyLoading;
|
|
||||||
Database.ChangeTracker.Clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="ValidationException">
|
/// <exception cref="ValidationException">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user