Example #1
0
    private void CreatePreview()
    {
        Person       currentPerson = Person.FromIdentity(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
        Organization org           = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue));

        if (this.DropGeographies.SelectedIndex > -1)
        {
            Geography geo = Geography.FromIdentity(Convert.ToInt32(this.DropGeographies.SelectedValue));

            WelcomeMail welcomemail = new WelcomeMail();
            welcomemail.pSubject     = this.TextSubject.Text;
            welcomemail.pBodyContent = this.TextBody.Text;
            welcomemail.pOrgName     = org.MailPrefixInherited;

            welcomemail.pGeographyName = "";
            if (geo.Identity != Geography.RootIdentity)
            {
                welcomemail.pGeographyName = geo.Name;
            }

            OutboundMail fake = welcomemail.CreateOutboundFake(currentPerson, org, geo);
            this.LiteralPreview.Text = fake.RenderHtml(currentPerson, org.DefaultCountry.Culture);
        }

        this.TextBody.Focus();
    }
Example #2
0
 protected override void Validation()
 {
     theMail             = new WelcomeMail(_Content, _EnableAutoSend);
     theMail.TheMailType = MailType.GetById(_MailTypeId);
     if (_MailTypeId.Equals(MailType.WelcomeMail.Id))
     {
         theMail.VaildateTheContent();
     }
 }
        public void GetLastestWelcomeMailTest()
        {
            BllInstance.WelcomeMailBllInstance.SaveWelcomeMail("WelcomeMail1 #Name#", false, 0);
            BllInstance.WelcomeMailBllInstance.SaveWelcomeMail("WelcomeMail2 #Name#", false, 0);
            BllInstance.WelcomeMailBllInstance.SaveWelcomeMail("WelcomeMail3 #Name#", false, 0);
            WelcomeMail welcomeMail = BllInstance.WelcomeMailBllInstance.GetLastestWelcomeMail();

            Assert.AreEqual(welcomeMail.Content, "WelcomeMail3 #Name#");
        }
Example #4
0
 public HomeController(IMemberRepository memberRepository,
                       IDonorRepository donorRepository,
                       ICaseRepository caseRepository,
                       IStoryRepository storyRepository,
                       WelcomeMail welcomeMail)
 {
     _memberRepository = memberRepository;
     _donorRepository  = donorRepository;
     _caseRepository   = caseRepository;
     _storyRepository  = storyRepository;
     _welcomeMail      = welcomeMail;
 }
Example #5
0
        //private const string _DBMailType = "MailType";

        public void AddWelcomeMail(WelcomeMail aNewMail)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Parameters.Add(_PKID, SqlDbType.Int).Direction       = ParameterDirection.Output;
            cmd.Parameters.Add(_Content, SqlDbType.Text).Value       = aNewMail.Content;
            cmd.Parameters.Add(_EnableAutoSend, SqlDbType.Int).Value = aNewMail.EnableAutoSend ? 1 : 0;
            cmd.Parameters.Add(_MailType, SqlDbType.Int).Value       = aNewMail.TheMailType.Id;
            int pkidOut;

            SqlHelper.ExecuteNonQueryReturnPKID("WelcomeMailInsert", cmd, out pkidOut);
            aNewMail.Id = pkidOut;
        }
        public void MailTypeChange(string id)
        {
            _TheView.AutoSend = false;
            _TheView.Content  = string.Empty;
            WelcomeMail theWelcomeMail = BllInstance.WelcomeMailBllInstance.GetLastestWelcomeMailByTypeID(Convert.ToInt32(id));

            if (theWelcomeMail == null)
            {
                _TheView.TheMessage = _LackData;
                return;
            }
            _TheView.AutoSend = theWelcomeMail.EnableAutoSend;
            _TheView.Content  = theWelcomeMail.Content;
        }
Example #7
0
 public WelcomeMail GetLastestWelcomeMail()
 {
     using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetLastestWelcomeMail", new SqlCommand()))
     {
         while (sdr.Read())
         {
             bool        enableAutoSend = int.Parse(sdr[_DBEnableAutoSend].ToString()) > 0 ? true : false;
             WelcomeMail theObj         = new WelcomeMail(sdr[_DBContent].ToString(), enableAutoSend);
             theObj.Id = int.Parse(sdr[_DBPKID].ToString());
             return(theObj);
         }
         return(null);
     }
 }
Example #8
0
        public WelcomeMail GetLastestWelcomeMailByTypeID(int mailTypeId)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Parameters.Add(_MailType, SqlDbType.Int).Value = mailTypeId;
            using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetLastestWelcomeMailByTypeID", cmd))
            {
                while (sdr.Read())
                {
                    bool        enableAutoSend = int.Parse(sdr[_DBEnableAutoSend].ToString()) > 0 ? true : false;
                    WelcomeMail theObj         = new WelcomeMail(sdr[_DBContent].ToString(), enableAutoSend);
                    theObj.Id          = int.Parse(sdr[_DBPKID].ToString());
                    theObj.TheMailType = MailType.GetById(mailTypeId);
                    return(theObj);
                }
                return(null);
            }
        }
        protected override void Validation()
        {
            //modify by liudan 2009-08-18 _TheWelcomeMail = _TheDal.GetLastestWelcomeMail();
            _TheWelcomeMail = _TheDal.GetLastestWelcomeMailByTypeID(MailType.WelcomeMail.Id);
            if (_TheWelcomeMail == null)
            {
                _VaildateSuccess = false;
                return;
            }
            if (!_TheWelcomeMail.EnableAutoSend)
            {
                _VaildateSuccess = false;
                return;
            }

            if (_TheGoodMailAddress.Count == 0 || _TheGoodMailAddress.Count >= 10)
            {
                _VaildateSuccess = false;
                return;
            }

            _VaildateSuccess = true;
        }
Example #10
0
        public static string CreateWelcomeMail (Person person, Organization organization)
        {
            // for this person, iterate over all applicable geographies and organizations

            Organizations orgLine = organization.GetLine();
            Geographies geoLine = person.Geography.GetLine();

            orgLine.Reverse(); // Start at the most local org

            Dictionary<int,bool> orgMailedLookup = new Dictionary<int, bool>();

            int delay = 0;
            string result = string.Empty;
            Random random = new Random();

            foreach (Organization org in orgLine)
            {
                foreach (Geography geo in geoLine) // but at the top geography
                {
                    AutoMail autoMail = AutoMail.FromTypeOrganizationAndGeography(AutoMailType.Welcome, org, geo);

                    if (autoMail == null)
                    {
                        continue;
                    }

                    Person lead = null;
                    string geoName = geo.Name;

                    try
                    {
                        lead = Roles.GetLocalLead(org, geo);
                        orgMailedLookup[org.Identity] = true; // Make sure that the chairman doesn't mail at a lower level
                    }
                    catch (ArgumentException)
                    {
                    }

                    if (lead == null && !orgMailedLookup.ContainsKey(org.Identity))
                    {
                        // If we get here, there is a mail template at the highest possible geo for this org, but no local lead.
                        // That's usually the case with board-centric organizations rather than executive-centric.
                        // Try to mail from chairman rather than the local lead.
                       
                        try
                        {
                            orgMailedLookup[org.Identity] = true;
                            lead = Roles.GetChairman(org);
                            geoName = "Chairman";
                        }
                        catch (ArgumentException)
                        {
                        }
                    }

                    if (lead == null)
                    {
                        // ok, give up if there isn't a chairman either or if we've already mailed this org from the chairman
                        continue;
                    }

                    // TODO: fetch lead from roles
                    WelcomeMail welcomemail = new WelcomeMail();

                    welcomemail.pOrgName = org.MailPrefixInherited;

                    welcomemail.pGeographyName = "";
                    if (geo.Identity != Geography.RootIdentity)
                    {
                        welcomemail.pGeographyName = geo.Name;
                    }

                    welcomemail.pBodyContent = autoMail.Body;
                    welcomemail.pSubject = autoMail.Title;
                    
                    OutboundMail newMail = welcomemail.CreateOutboundMail (lead, OutboundMail.PriorityNormal,
                                                                            org, geo, DateTime.Now.AddMinutes(delay));
                    newMail.AddRecipient(person.Identity, false);
                    newMail.SetRecipientCount(1);
                    newMail.SetResolved();
                    newMail.SetReadyForPickup();
                    
                    result += String.Format(" - {0}/{1} by {2} (",
                                            org.NameShort, geoName, lead.Canonical);
                    if (delay == 0)
                    {
                        result += "sent now";
                        delay += 37;
                    }
                    else
                    {
                        result += "sending at " + DateTime.Now.AddMinutes(delay).ToString("HH:mm");
                        delay += 31 + random.Next(52);
                    }
                    result += ")\r\n";
                }
            }

            if (result.Length < 4)
            {
                result = "none\r\n";
            }

            return result;
        }
Example #11
0
        public static string CreateWelcomeMail(Person person, Organization organization)
        {
            // for this person, iterate over all applicable geographies and organizations

            Organizations orgLine = organization.GetLine();
            Geographies   geoLine = person.Geography.GetLine();

            orgLine.Reverse(); // Start at the most local org

            Dictionary <int, bool> orgMailedLookup = new Dictionary <int, bool>();

            int    delay  = 0;
            string result = string.Empty;
            Random random = new Random();

            foreach (Organization org in orgLine)
            {
                foreach (Geography geo in geoLine) // but at the top geography
                {
                    AutoMail autoMail = AutoMail.FromTypeOrganizationAndGeography(AutoMailType.Welcome, org, geo);

                    if (autoMail == null)
                    {
                        continue;
                    }

                    Person lead    = null;
                    string geoName = geo.Name;

                    try
                    {
                        lead = Roles.GetLocalLead(org, geo);
                        orgMailedLookup[org.Identity] = true;
                        // Make sure that the chairman doesn't mail at a lower level
                    }
                    catch (ArgumentException)
                    {
                    }

                    if (lead == null && !orgMailedLookup.ContainsKey(org.Identity))
                    {
                        // If we get here, there is a mail template at the highest possible geo for this org, but no local lead.
                        // That's usually the case with board-centric organizations rather than executive-centric.
                        // Try to mail from chairman rather than the local lead.

                        try
                        {
                            orgMailedLookup[org.Identity] = true;
                            lead    = Roles.GetChairman(org);
                            geoName = "Chairman";
                        }
                        catch (ArgumentException)
                        {
                        }
                    }

                    if (lead == null)
                    {
                        // ok, give up if there isn't a chairman either or if we've already mailed this org from the chairman
                        continue;
                    }

                    // TODO: fetch lead from roles
                    WelcomeMail welcomemail = new WelcomeMail();

                    welcomemail.pOrgName = org.MailPrefixInherited;

                    welcomemail.pGeographyName = "";
                    if (geo.Identity != Geography.RootIdentity)
                    {
                        welcomemail.pGeographyName = geo.Name;
                    }

                    welcomemail.pBodyContent = autoMail.Body;
                    welcomemail.pSubject     = autoMail.Title;

                    OutboundMail newMail = welcomemail.CreateOutboundMail(lead, OutboundMail.PriorityNormal,
                                                                          org, geo, DateTime.Now.AddMinutes(delay));
                    newMail.AddRecipient(person.Identity, false);
                    newMail.SetRecipientCount(1);
                    newMail.SetResolved();
                    newMail.SetReadyForPickup();

                    result += String.Format(" - {0}/{1} by {2} (",
                                            org.NameShort, geoName, lead.Canonical);
                    if (delay == 0)
                    {
                        result += "sent now";
                        delay  += 37;
                    }
                    else
                    {
                        result += "sending at " + DateTime.Now.AddMinutes(delay).ToString("HH:mm");
                        delay  += 31 + random.Next(52);
                    }
                    result += ")\r\n";
                }
            }

            if (result.Length < 4)
            {
                result = "none\r\n";
            }

            return(result);
        }
Example #12
0
    private void CreatePreview ()
    {
        Person currentPerson = Person.FromIdentity(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
        Organization org = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue));
        if (this.DropGeographies.SelectedIndex > -1)
        {

            Geography geo = Geography.FromIdentity(Convert.ToInt32(this.DropGeographies.SelectedValue));

            WelcomeMail welcomemail = new WelcomeMail();
            welcomemail.pSubject = this.TextSubject.Text;
            welcomemail.pBodyContent = this.TextBody.Text;
            welcomemail.pOrgName = org.MailPrefixInherited;

            welcomemail.pGeographyName = "";
            if (geo.Identity != Geography.RootIdentity)
            {
                welcomemail.pGeographyName = geo.Name;
            }

            OutboundMail fake = welcomemail.CreateOutboundFake(currentPerson, org, geo);
            this.LiteralPreview.Text = fake.RenderHtml(currentPerson, org.DefaultCountry.Culture);
        }

        this.TextBody.Focus();
    }