mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-04 03:27:14 -05: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;
 | 
				
			||||||
@ -304,25 +306,17 @@ 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;
 | 
					 | 
				
			||||||
		Database.ChangeTracker.LazyLoadingEnabled = false;
 | 
					 | 
				
			||||||
		try
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		T resource = await GetWithTracking(id);
 | 
							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">
 | 
				
			||||||
	/// You can throw this if the resource is illegal and should not be saved.
 | 
						/// You can throw this if the resource is illegal and should not be saved.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user