using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using gehGassi.Domain.Base;
using gehGassi.Domain.Common;
using gehGassi.Domain.Localization;
namespace gehGassi.Domain.Subscriptions
{
///
/// Repräsentiert ein Abonnement
///
public class Subscription : SyncEntityLocalizable, IAuditable
{
///
/// Subscription Code - Produkt ID für Stores
///
[Required]
[MaxLength(128)]
public string Code { get; set; }
///
/// Dauer des Abonnements
///
[Required]
public SubscriptionLength Length { get; set; }
///
/// Preis des Abonnements in Euro
///
[Required]
public decimal Price { get; set; }
///
/// Art des Abonnements - für welchen Benutzer-Typ?
///
[Required]
public AppMode AppMode { get; set; }
///
/// Name des Abonnements
///
[Localized]
[NotMapped]
public string Name
{
get => Get("Name", GetLanguage());
set => Set("Name", GetLanguage(), value);
}
///
/// Name - Inhalt
///
[Column]
public string NameLocalized { get; set; }
///
/// Beschreibung des Abonnements
///
[Localized]
[NotMapped]
public string Description
{
get => Get("Description", GetLanguage());
set => Set("Description", GetLanguage(), value);
}
///
/// Beschreibung - Inhalt
///
[Column]
public string DescriptionLocalized { get; set; }
///
/// Ist das Abonnement aktiv?
///
[Required]
public bool Enabled { get; set; }
///
/// Zeit in Tagen die als Toleranz bei Ablauf akzeptiert wird
///
[Required]
public int GracePeriodInDays { get; set; }
///
/// Ist das Abonnement ausgeblendet?
///
[Required]
public bool Hidden { get; set; }
///
/// Optional: the Max registered date of the app user to see this subscription
///
public DateTimeOffset? MaxRegisteredDate { get; set; }
///
/// Hilfsmethode die die Ablaufzeit des Abonnements berechnet
///
/// Ablaufdatum
public DateTimeOffset GetExpiration(DateTimeOffset date)
{
switch (Length)
{
case SubscriptionLength.OneWeek:
return date.AddDays(7);
case SubscriptionLength.OneMonth:
return date.AddMonths(1);
case SubscriptionLength.ThreeMonths:
return date.AddMonths(3);
case SubscriptionLength.SixMonths:
return date.AddMonths(6);
case SubscriptionLength.OneYear:
return date.AddYears(1);
default:
return date;
}
}
///
/// Hilfsmethode die die Ablaufzeit des Abonnements berechnet und die Tolranzzeit hinzufügt
///
/// Datum
/// Ablaufdatum mit toleranz
public DateTimeOffset GetExpirationWithGrace(DateTimeOffset date)
{
var expirationDate = GetExpiration(date);
return expirationDate.AddDays(GracePeriodInDays);
}
#region IAuditable
///
/// Gibt den eindeutigen Key für die Entität zurück;
/// Hier als String gelöst, weil damit auch kombinierte Schlüssel möglich sind.
///
/// Eindeutiger Key
public string AuditKey()
{
return Id.ToString();
}
///
/// Gibt den Objektnamen bzw. die Tabelle der Entität zurück
///
/// Objektnamen
public string AuditTable()
{
return "Subscriptions";
}
public AuditableOptions Options()
{
return AuditableOptions.Create | AuditableOptions.Edit | AuditableOptions.Delete;
}
#endregion
}
///
/// Repräsentiert ein Abonnement mit Namen aufgleöst
///
public class SubscriptionWithNames : SyncEntityLocalizableVw
{
///
/// Subscription Code - Produkt ID für Stores
///
public string Code { get; set; }
///
/// Dauer des Abonnements
///
public SubscriptionLength Length { get; set; }
///
/// Preis des Abonnements in Euro
///
public decimal Price { get; set; }
///
/// Art des Abonnements - für welchen Benutzer-Typ?
///
public AppMode AppMode { get; set; }
///
/// Name des Abonnements
///
public string Name { get; set; }
///
/// Name - Inhalt
///
[Column]
public string NameLocalized { get; set; }
///
/// Beschreibung des Abonnements
///
public string Description { get; set; }
///
/// Beschreibung - Inhalt
///
[Column]
public string DescriptionLocalized { get; set; }
///
/// Ist das Abonnement aktiv?
///
public bool Enabled { get; set; }
///
/// Zeit in Tagen die als Toleranz bei Ablauf akzeptiert wird
///
public int GracePeriodInDays { get; set; }
///
/// Ist das Abonnement ausgeblendet?
///
public bool Hidden { get; set; }
///
/// Optional: the Max registered date of the app user to see this subscription
///
public DateTimeOffset? MaxRegisteredDate { get; set; }
///
/// Anzahl der Abonnements insgesamt
///
public int SubscriptionCountTotal { get; set; }
///
/// Anzahl der aktiven Abonnements
///
public int SubscriptionCountActive { get; set; }
///
/// Anzahl der inaktiven Abonnements
///
public int SubscriptionCountInactive{ get; set; }
}
}