Files
mixtape/zero.Core/Collections/Interceptors/CollectionInterceptorParameters.cs
T

112 lines
2.7 KiB
C#
Raw Normal View History

2021-08-26 13:39:30 +02:00
using FluentValidation;
using Raven.Client.Documents.Session;
using System.Collections.Generic;
using zero.Core.Database;
using zero.Core.Entities;
using zero.Core.Extensions;
namespace zero.Core.Collections
{
public abstract partial class CollectionInterceptor<T> : ICollectionInterceptor<T> where T : ZeroEntity
2021-08-26 13:39:30 +02:00
{
public class Parameters
2021-08-26 13:39:30 +02:00
{
/// <summary>
/// The current zero context
/// </summary>
public IZeroContext Context { get; set; }
/// <summary>
/// Raven document store
/// </summary>
public IZeroStore Store { get; set; }
/// <summary>
/// Currently loaded document session
/// </summary>
public IAsyncDocumentSession Session { get; set; }
/// <summary>
/// Validator for the affected entity
/// </summary>
public IValidator<T> Validator { get; set; }
/// <summary>
/// Access to the collection
/// </summary>
public ICollectionBase<T> Collection { get; set; }
2021-08-26 13:39:30 +02:00
/// <summary>
/// Parameters from the interceptor which ran on before the operation (only available for completed operations)
/// </summary>
public Dictionary<string, object> Properties { get; set; } = new();
/// <summary>
/// Get a typed property
/// </summary>
public TProp Property<TProp>(string key) => Properties.GetValueOrDefault<TProp>(key);
/// <summary>
/// Get a typed property
/// </summary>
public bool TryGetProperty<TProp>(string key, out TProp property) => Properties.TryGetValue(key, out property);
}
public class ParametersWithModel : Parameters
2021-08-26 13:39:30 +02:00
{
/// <summary>
/// The model which is affected
/// </summary>
public T Model { get; set; }
}
public class CreateParameters : ParametersWithModel
2021-08-26 13:39:30 +02:00
{
}
public class UpdateParameters : ParametersWithModel
2021-08-26 13:39:30 +02:00
{
/// <summary>
/// The Id of the model which is updated
/// </summary>
public string Id { get; set; }
}
2021-09-24 10:38:59 +02:00
public class SaveParameters : ParametersWithModel
{
/// <summary>
/// The Id of the model which is saving (empty when creating)
/// </summary>
public string Id { get; set; }
2021-10-04 15:53:50 +02:00
/// <summary>
/// Whether this instruction is an update
/// </summary>
public bool IsUpdate { get; set; }
/// <summary>
/// Whether this instruction is create
/// </summary>
public bool IsCreate => !IsUpdate;
2021-09-24 10:38:59 +02:00
}
public class DeleteParameters : ParametersWithModel
2021-08-26 13:39:30 +02:00
{
/// <summary>
/// The id of the model which is deleted
/// </summary>
public string Id { get; set; }
}
public class PurgeParameters : Parameters
{
}
2021-08-26 13:39:30 +02:00
}
}