using SiberTek.Xenta.Entities;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Managers;
namespace SiberTek.Xenta.Extensions
{
/// <summary>
/// Contains message manager extension methods
/// </summary>
public static class CoreMessageManagerExtesion
{
#region Methods
public static bool SendContactMessage(this MessageManager mgr, int languageID, string replyTo, string msgSubject, string msgText)
{
MessageTemplateInfo template = mgr.GetMessageTemplateByName(languageID, "contact-message");
if(template == null)
{
return false;
}
string subject = template.Subject;
string text = template.Text;
subject = subject.Replace("[Token:Message.Subject]", msgSubject);
subject = subject.Replace("[Token:Message.From]", replyTo);
text = text.Replace("[Token:Message.Subject]", msgSubject);
text = text.Replace("[Token:Message.From]", replyTo);
text = text.Replace("[Token:Message.Text]", msgText);
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, template.To, template.BccTo, replyTo, subject, text);
return message != null;
}
public static bool SendAccountInstructions(this MessageManager mgr, int userID)
{
UserInfo user = UserManager.Instance.GetUser(userID);
if(user == null)
{
return false;
}
MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "account-instructions");
if(template == null)
{
return false;
}
string subject = template.Subject;
string text = template.Text;
text = text.Replace("[Token:User.FullName]", user.FullName);
text = text.Replace("[Token:User.Username]", user.Username);
text = text.Replace("[Token:User.Email]", user.Email);
text = text.Replace("[Token:User.Guid]", user.Guid.ToString());
text = text.Replace("[Token:User.Password]", user.ClearTextPassword);
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, subject, text);
return message != null;
}
public static bool SendSubscriptionInstructions(this MessageManager mgr, int subscriptionID)
{
SubscriptionInfo subscription = SubscriptionManager.Instance.GetSubscription(subscriptionID);
if(subscription == null)
{
return false;
}
MessageTemplateInfo template = mgr.GetMessageTemplateByName(subscription.LanguageID, "subscription-instructions");
if(template == null)
{
return false;
}
string subject = template.Subject;
string text = template.Text;
text = text.Replace("[Token:Subscription.Guid]", subscription.Guid.ToString());
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, subscription.Email, template.BccTo, subject, text);
return message != null;
}
public static bool SendPasswordReminder(this MessageManager mgr, int userID)
{
UserInfo user = UserManager.Instance.GetUser(userID);
if(user == null)
{
return false;
}
MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "password-reminder");
if(template == null)
{
return false;
}
string subject = template.Subject;
string text = template.Text;
text = text.Replace("[Token:User.FullName]", user.FullName);
text = text.Replace("[Token:User.Username]", user.Username);
text = text.Replace("[Token:User.Email]", user.Email);
text = text.Replace("[Token:User.Guid]", user.Guid.ToString());
text = text.Replace("[Token:User.Password]", user.ClearTextPassword);
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, subject, text);
return message != null;
}
#endregion
}
}