Esempio n. 1
0
        public Promotion AddReferralPromotion(int numberReferred)
        {
            int discount = numberReferred*DiscountPerFriendReferred;

            var promotion = new Promotion
            {
                Created = DateTime.Now,
                Description = string.Format("{0}% Discount earned for referring {1} friends", discount, numberReferred),
                Discount = discount,
                Expires = DateTime.Now.AddYears(1)
            };

            promotionRepository.Add(promotion);
            promotionRepository.UnitOfWork.Commit();

            return promotion;
        }
Esempio n. 2
0
        public void SendReferralPromotionMessageToUser(Promotion promotion, IUser user)
        {
            var templateBody = TemplateBody(templateSettings.GetReferralPromotion());

            var replacementKeyValues = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("{{BaseUrl}}", templateSettings.GetBasePath()),
                new KeyValuePair<string, string>("{{FullName}}", user.FullName ?? user.Email),
                new KeyValuePair<string, string>("{{Discount}}", promotion.Discount.ToString()),
                new KeyValuePair<string, string>("{{Code}}", promotion.Code),
                new KeyValuePair<string, string>("{{Expires}}", promotion.Expires.Value.ToString("dd/MM/yyyy"))
            };

            string body = templateManager.PopulateTemplate(templateBody, replacementKeyValues);

            Logger.Info("Sending Referral Promotion Message");

            string subject = string.Format("Your promotional code for {0}% discount from Website Upd8", promotion.Discount);

            var toAddress = emailAddressSettings.CreateEmailAddress(user.Email, user.FullName ?? user.Email);
            var fromAddress = emailAddressSettings.GetInfoEmailAddress();

            if (emailer.TrySendMail(toAddress, fromAddress, subject, body))
            {
                Logger.Info("Send succeeded");
            }
        }