Ejemplo n.º 1
0
        /// <summary>
        /// Emails the user notice of the application status change
        /// </summary>
        private void EmailStatusChange(int userId, int schemeId, int templateId)
        {
            //get the users email
            var user = PemsEntities.Users.FirstOrDefault(x => x.UserID == userId);

            if (user != null)
            {
                //now get the DiscountSchemeEmailTemplate for this customer and templateID passed in. this will get us the subject and body fo the email
                var dsEmailTemplate = PemsEntities.DiscountSchemeEmailTemplates.FirstOrDefault(x => x.CustomerId == user.DefaultCustomerID && x.EmailTemplateTypeId == templateId);
                if (dsEmailTemplate != null)
                {
                    var    to      = user.UserEmail;
                    var    from    = "*****@*****.**";
                    string subject = dsEmailTemplate.EmailSubject;
                    var    body    = dsEmailTemplate.EmailText;
                    //now lets get the "from". get the DSCustomerInfo for this templateID , customerid and scheme id
                    var dsCustomerInfo =
                        PemsEntities.DiscountSchemeCustomerInfoes.FirstOrDefault(
                            x => x.CustomerId == user.DefaultCustomerID &&
                            x.DiscountSchemeEmailTemplateId == dsEmailTemplate.DiscountSchemeEmailTemplateId &&
                            x.DiscountSchemeId == schemeId);
                    if (dsCustomerInfo != null)
                    {
                        from = dsCustomerInfo.FromEmailAddress;
                    }

                    //send email to user
                    var mailer = new EmailFactory();
                    mailer.UserSchemeStatus(to, from, subject, body, "EmailStatusChange").Send();
                }
            }
        }