198 lines
7.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using gehGassi.Domain.Localization;
namespace gehGassi.Domain.Base
{
/// <summary>
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften verfügt
/// </summary>
public class SyncEntity : ISyncEntity
{
/// <summary>
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
/// </summary>
[Key]
[MaxLength(128)]
public string Id { get; set; }
/// <summary>
/// Index für schnelle Suche.
/// Muss via Fluent-API im DB-Context gesetzt werden!
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Index { get; set; }
/// <summary>
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
/// </summary>
[Timestamp]
public byte[] Version { get; set; }
/// <summary>
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
/// <summary>
/// Gibt an ob diese Entität gelöscht wurde
/// </summary>
public bool Deleted { get; set; }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
/// <summary>
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften und Übersetzungen verfügt
/// </summary>
public class SyncEntityLocalizable : LocalizableBase, ISyncEntity
{
/// <summary>
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
/// </summary>
[Key]
[MaxLength(128)]
public string Id { get; set; }
/// <summary>
/// Index für schnelle Suche.
/// Muss via Fluent-API im DB-Context gesetzt werden!
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Index { get; set; }
/// <summary>
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
/// </summary>
[Timestamp]
public byte[] Version { get; set; }
/// <summary>
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
/// <summary>
/// Gibt an ob diese Entität gelöscht wurde
/// </summary>
public bool Deleted { get; set; }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
/// <summary>
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften verfügt für Views
/// </summary>
public class SyncEntityVw : ISyncEntity
{
/// <summary>
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
/// </summary>
public string Id { get; set; }
/// <summary>
/// Index für schnelle Suche.
/// Muss via Fluent-API im DB-Context gesetzt werden!
/// </summary>
public long Index { get; set; }
/// <summary>
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
/// </summary>
public byte[] Version { get; set; }
/// <summary>
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; }
/// <summary>
/// Gibt an ob diese Entität gelöscht wurde
/// </summary>
public bool Deleted { get; set; }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
/// <summary>
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften und Übersetzungen verfügt für Views
/// </summary>
public class SyncEntityLocalizableVw : LocalizableBase, ISyncEntity
{
/// <summary>
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
/// </summary>
public string Id { get; set; }
/// <summary>
/// Index für schnelle Suche.
/// Muss via Fluent-API im DB-Context gesetzt werden!
/// </summary>
public long Index { get; set; }
/// <summary>
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
/// </summary>
public byte[] Version { get; set; }
/// <summary>
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; }
/// <summary>
/// Gibt an ob diese Entität gelöscht wurde
/// </summary>
public bool Deleted { get; set; }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
}