Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve email sender for organization
        /// </summary>
        /// <param name="organizationId">organization id</param>
        /// <returns>base email sender</returns>
        private BaseEmailSender GetEmailSender(long?organizationId)
        {
            // get cached email sernder
            BaseEmailSender sender = GetCachedEmailSender(organizationId);

            if (sender != null)
            {
                return(sender);
            }

            Organization org = null;

            if (!organizationId.HasValue || organizationId <= 0)
            {
                org = dbContext.Organizations.FirstOrDefault(p => !p.ParentId.HasValue);
            }
            else
            {
                org = dbContext.Organizations.Find(organizationId);
            }

            if (org == null)
            {
                throw new ArgumentNullException("organization", string.Format("Organization {0} not found", organizationId));
            }

            sender = GetOrganizationEmailSender(org);
            SetCachedEmailSender(sender, org);

            return(sender);
        }
Ejemplo n.º 2
0
 private void SetCachedEmailSender(BaseEmailSender sender, Organization org)
 {
     if (!org.ParentId.HasValue)
     {
         cache.SetString(CacheKeys.EmailSettingsRoot, sender.Settings.ToString());
     }
     else
     {
         cache.SetString(string.Format(CacheKeys.EmailSettingsOrg, org.Id), sender.Settings.ToString());
     }
 }