public static ShortUrl GetShortUrlByUrl(string url) { var cachedUrl = _Cache[url] as ShortUrl; if(cachedUrl == null) { var context = new WSDataContext(); cachedUrl = context.ShortUrls.Where(m => m.Url == url).SingleOrDefault(); if (cachedUrl == null) { cachedUrl = new ShortUrl() { Url = url, CreatedDate = DateTime.Now, LastUpdatedDate = DateTime.Now }; context.ShortUrls.Add(cachedUrl); context.SaveChanges(); _Cache.Add(url, cachedUrl, new CacheItemPolicy()); } } return cachedUrl; }
public async Task<bool> CreateAsync(NewsletterSubscriber dbSubscriber) { bool isDuplicate = false; using (WSDataContext context = new WSDataContext()) { if (context.NewsletterSubscribers.Where(m => m.EmailAddress == dbSubscriber.EmailAddress).Count() == 0) { if (HttpContext.Current != null && HttpContext.Current.Request != null) { dbSubscriber.IPAddress = HttpContext.Current.Request.UserHostAddress; } else { dbSubscriber.IPAddress = null; } context.NewsletterSubscribers.Add(dbSubscriber); context.SaveChanges(); dbSubscriber.SubscriberId = dbSubscriber.SubscriberId; NameValueCollection messageVars = new NameValueCollection(); messageVars.Add("%%NAME%%", dbSubscriber.Name); MailManager.SendEmail("NewsletterSubscriptionConfirmation", dbSubscriber.Name, dbSubscriber.EmailAddress, null, messageVars); WSConfigurationSection config = WSConfigurationManager.GetSection(); if (config.NewsletterSubscriberNotificationSubscribers != null && config.NewsletterSubscriberNotificationSubscribers.Count > 0) { List<string> subscriberEmails = new List<string>(); foreach (WSNotificationSubscriberElement subscriberConfig in config.NewsletterSubscriberNotificationSubscribers) { if (subscriberConfig.Enabled) { subscriberEmails.Add(subscriberConfig.EmailAddress); } } messageVars = new NameValueCollection(); messageVars.Add("%%SUBSCRIBER_ID%%", dbSubscriber.SubscriberId.ToString()); messageVars.Add("%%DATE%%", dbSubscriber.CreatedDate.ToLongDateString()); messageVars.Add("%%NAME%%", dbSubscriber.Name); messageVars.Add("%%EMAIL_ADDRESS%%", dbSubscriber.EmailAddress); messageVars.Add("%%IP_ADDRESS%%", String.IsNullOrEmpty(dbSubscriber.IPAddress) ? "NA" : dbSubscriber.IPAddress); MailManager.SendEmail("NewsletterSubscribed", subscriberEmails, null, messageVars); } } else { isDuplicate = true; } } return isDuplicate; }
public async Task CreateAsync(Contact contact) { if(contact == null) { throw new ArgumentNullException("contact"); } using (WSDataContext context = new WSDataContext()) { if (HttpContext.Current != null && HttpContext.Current.Request != null) { contact.IPAddress = HttpContext.Current.Request.UserHostAddress; } else { contact.IPAddress = null; } Context.Contacts.Add(contact); var result = await Context.SaveChangesAsync(); if (result > 0) { NameValueCollection messageVars = new NameValueCollection(); messageVars.Add("%%NAME%%", contact.Name); MailManager.SendEmail("ContactConfirmation", contact.Name, contact.EmailAddress, null, messageVars); WSConfigurationSection config = WSConfigurationManager.GetSection(); if (config.ContactNotificationSubscribers != null && config.ContactNotificationSubscribers.Count > 0) { List<string> subscriberEmails = new List<string>(); foreach (WSNotificationSubscriberElement subscriberConfig in config.ContactNotificationSubscribers) { if (subscriberConfig.Enabled) { subscriberEmails.Add(subscriberConfig.EmailAddress); } } messageVars = new NameValueCollection(); messageVars.Add("%%CONTACT_ID%%", contact.ContactId.ToString()); messageVars.Add("%%DATE%%", contact.CreatedDate.ToLongDateString()); messageVars.Add("%%NAME%%", contact.Name); messageVars.Add("%%EMAIL_ADDRESS%%", contact.EmailAddress); messageVars.Add("%%ORGANIZATION_NAME%%", String.IsNullOrEmpty(contact.OrganizationName) ? "NA" : contact.OrganizationName); messageVars.Add("%%JOB_TITLE%%", String.IsNullOrEmpty(contact.JobTitle) ? "NA" : contact.JobTitle); messageVars.Add("%%CITY%%", String.IsNullOrEmpty(contact.City) ? "NA" : contact.City); messageVars.Add("%%IP_ADDRESS%%", String.IsNullOrEmpty(contact.IPAddress) ? "NA" : contact.IPAddress); messageVars.Add("%%RELATIONSHIP%%", contact.Relationship.ToString()); messageVars.Add("%%COMMENTS%%", String.IsNullOrEmpty(contact.Comments) ? "NA" : contact.Comments); MailManager.SendEmail("ContactReceived", subscriberEmails, null, messageVars); } } } }
public ShortUrl FindByUrlAsync(string url) { if (url == null) { throw new ArgumentNullException("url"); } using (WSDataContext context = new WSDataContext()) { var ReturnUrl = Context.ShortUrls.Where(c => c.Url == url).SingleOrDefault(); return ReturnUrl; } }
public async Task CreateAsync(ShortUrl shortUrl) { if (shortUrl == null) { throw new ArgumentNullException("shortUrl"); } using (WSDataContext context = new WSDataContext()) { Context.ShortUrls.Add(shortUrl); var result = await Context.SaveChangesAsync(); } }
public static ShortUrl GetShortUrlById(int id) { var cachedUrl = _Cache[id.ToString()] as ShortUrl; if (cachedUrl == null) { var context = new WSDataContext(); cachedUrl = context.ShortUrls.Where(m => m.Id == id).SingleOrDefault(); if (cachedUrl != null) { _Cache.Add(id.ToString(), cachedUrl, new CacheItemPolicy()); } } return cachedUrl; }
public async static void Subscribe(string list, NewsletterSubscriber subscriber) { MailChimpListSubscription subscription = new MailChimpListSubscription(); var context = new WSDataContext(); NewsletterManager manager = new NewsletterManager(context); subscription.Email = subscriber.EmailAddress; subscription.ListId = list; subscription.MergeData = new List<KeyValuePair<string, object>>(); subscription.MergeData.Add(new KeyValuePair<string,object>("NAME",subscriber.Name)); subscription.DoubleOptIn = true; subscription.ReplaceInterests = true; subscription.SendWelcome = false; subscription.UpdateExisting = false; MailChimpService service = new MailChimpService(); await manager.CreateAsync(subscriber); service.Subscribe(subscription); }
public WorkshopRepository(WSDataContext context) { _dbContext = context; }
public NewsletterManager(WSDataContext context) : base(context) { }
public ShortUrlManager(WSDataContext context) : base(context) { }
public static void SendEmail(string templateName, string senderName, string senderEmail, string recipientName, string recipientEmail, NameValueCollection subjectVariables, NameValueCollection messageVariables) { MailAddress fromAddress = null; MailAddress toAddress = null; MailMessage msg = null; using (WSDataContext context = new WSDataContext()) { MailTemplate dbTemplate = (from t in context.MailTemplates where t.MailTemplateName == templateName select t).SingleOrDefault(); fromAddress = new MailAddress(senderEmail, senderName); toAddress = new MailAddress(recipientEmail, recipientName); msg = new MailMessage(fromAddress, toAddress); string body = dbTemplate.Message, subject = dbTemplate.Subject; if (messageVariables != null && messageVariables.Count > 0) { foreach (string key in messageVariables.AllKeys) { body = body.Replace(key, messageVariables[key]); } } if (subjectVariables != null && subjectVariables.Count > 0) { foreach (string key in subjectVariables.AllKeys) { subject = subject.Replace(key, subjectVariables[key]); } } msg.Body = body; msg.Subject = subject; msg.IsBodyHtml = dbTemplate.IsHtml; _SmtpClient.Send(msg); } }
public ContactManager(WSDataContext context) : base(context) { }