示例#1
0
        private bool UpdatePromotionalPricing(User user, Price price)
        {
            try
            {
                UserPrice uPrice = crumbsRepository.FindUserPriceByUserID(user.UserID, price.Type);
                if (uPrice == null)
                {
                    // no current promotions for this user - create a new one
                    UserPrice newUserPrice = new UserPrice()
                    {
                        User = user,
                        Price = price,
                        Subscribed = 0
                    };
                    crumbsRepository.InsertOrUpdateUserPrice(newUserPrice);
                }
                else if (uPrice.Subscribed == 0)
                {
                    if (uPrice.Price.Expiration < DateTime.Now)
                    {
                        // expired promotion found - replace it
                        uPrice.Price = price;
                        uPrice.Amount = 0;
                        uPrice.PaymentID = "";
                        crumbsRepository.InsertOrUpdateUserPrice(uPrice);
                    }
                    else
                    {
                        // un-expired promotion found - keep it
                        return false;
                    }
                }
                else
                {
                    // already subscribed - leave it alone
                    return false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
                return false;
            }

            return true;
        }
示例#2
0
        public bool SendMail(User user, Mailing mail, Price price, MidiFile file)
        {
            if (user.Email == null)
                return false;

            if (price != null)
            {
                if (UpdatePromotionalPricing(user, price) == false)
                    return false;
            }

            try
            {
                SmtpClient client = new SmtpClient("m02.internetmailserver.net", 587);
                client.EnableSsl = false;
                MailAddress from = new MailAddress("*****@*****.**", "PianoCrumbs.com");
                MailAddress to = new MailAddress(user.Email, "");
                MailMessage message = new MailMessage(from, to);
                message.Subject = mail.Subject;
                message.IsBodyHtml = true;

                string fileName = "";
                string urlAction = "";

                if (file != null)
                {
                    fileName = file.Name;
                    urlAction = Url.Action("MidiView", "Crumbs", new { id = file.MidiID, name = file.DisplayName }, "http");
                }

                string latestLinks = "";
                IQueryable<MidiFile> latestFiles = crumbsRepository.LatestCrumbs.Take(5);
                foreach (var item in latestFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    latestLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                string popualrLinks = "";
                IQueryable<MidiFile> popularFiles = crumbsRepository.RatedCrumbs.Take(5);
                foreach (var item in popularFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    popualrLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                message.Body = string.Format(mail.Text, user.UserName, fileName, urlAction, latestLinks, popualrLinks);

                string unsubLink = Url.Action("Unsubscribe", "Account", new { username = user.UserName, reset = CrumbsExtensions.HashResetParams(user.UserName, user.UserKey) }, Request.Url.Scheme);
                message.Body += "<p><a href='" + unsubLink + "'>Unsubscribe</a>";

                NetworkCredential myCreds = new NetworkCredential("*****@*****.**", "Crumbs123", "");
                client.Credentials = myCreds;

                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
                return false;
            }

            SentMail sent = new SentMail();
            sent.UserID = user.UserID;
            sent.MailID = mail.ID;
            sent.Date = DateTime.Now;

            crumbsRepository.InsertOrUpdateSentMail(sent);
            crumbsRepository.Save();

            return true;
        }