public static void Subscribe(User subscriber, Node target, NotificationFrequency frequency, string language, string sitePath, string siteUrl, bool isActive)
{
if (subscriber.Email == null)
{
throw new InvalidOperationException("Subscriber's email cannot be null.");
}
if (subscriber.Email.Length == 0)
{
throw new InvalidOperationException("Subscriber's email cannot be empty.");
}
var userName = subscriber.FullName;
if (String.IsNullOrEmpty(userName))
{
userName = subscriber.Username;
}
var subscription = new Subscription
{
UserEmail = subscriber.Email,
UserId = subscriber.Id,
UserPath = subscriber.Path,
UserName = userName,
ContentPath = target.Path,
Frequency = frequency,
Language = language,
IsActive = true,
SitePath = sitePath,
SiteUrl = siteUrl,
};
subscription.Save();
}