/// <summary> /// Validates that the entity can be modified by the current user. If the user does not have permissions, the method should throw an exception. /// </summary> /// <param name="entity"></param> /// <param name="stage"> /// The BeforeMap stage is called when an existing entity is loaded from the database and is about to be mapped. /// The AfterMap stage is called when the DTO was mapped to the entity and the entity is about to be saved. /// </param> protected virtual void ValidateModifyPermissions(TEntity entity, ModificationStage stage) { }
/// <summary> /// Validates that the entity can be modified by the current user. If the user does not have permissions, the method should throw an exception. /// </summary> /// <param name="cancellationToken"></param> /// <param name="entity"></param> /// <param name="stage"> /// The BeforeMap stage is called when an existing entity is loaded from the database and is about to be mapped. /// The AfterMap stage is called when the DTO was mapped to the entity and the entity is about to be saved. /// </param> protected virtual Task ValidateModifyPermissionsAsync(TEntity entity, ModificationStage stage, CancellationToken cancellationToken = default) { return(cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : Task.CompletedTask); }