Example #1
0
        /// <summary>
        /// Retrieves the default EmailTemplate for a specific email type
        /// </summary>
        /// <param name="emailType"></param>
        /// <returns></returns>
        public static EmailTemplate GetDefault(Config.EmailType emailType)
        {
            EmailTemplates emailTemplates = new EmailTemplates();

            emailTemplates.SortBy      = EmailSortBy.DateUpdatedDescending;
            emailTemplates.Page        = 1;
            emailTemplates.RecsPerPage = 1;
            emailTemplates.Active      = true;
            emailTemplates.EmailType   = emailType;
            emailTemplates.LoadDefault = true;
            emailTemplates.Load();
            if (emailTemplates.Count > 0)
            {
                return(emailTemplates[0]);
            }
            return(EmailTemplate.BlankTemplate);
        }
Example #2
0
        /// <summary>
        /// Loads the object from the database based on the inialized properties for the class
        /// </summary>
        public void Load()
        {
            EmailTemplates allTemplates = AllTemplates;

            foreach (EmailTemplate template in allTemplates)
            {
                this.Add(template);
            }

            if (SortBy != null)
            {
                switch (SortBy)
                {
                case EmailSortBy.EmailLabelAscending:
                    this.Sort((x, y) => x.EmailLabel.CompareTo(y.EmailLabel));
                    break;

                case EmailSortBy.EmailLabelDescending:
                    this.Sort((x, y) => y.EmailLabel.CompareTo(x.EmailLabel));
                    break;

                case EmailSortBy.DateUpdatedAscending:
                    this.Sort((x, y) => x.DateUpdated.CompareTo(y.DateUpdated));
                    break;

                case EmailSortBy.DateUpdatedDescending:
                    this.Sort((x, y) => y.DateUpdated.CompareTo(x.DateUpdated));
                    break;

                case EmailSortBy.FromAddressAscending:
                    this.Sort((x, y) => x.FromAddress.CompareTo(y.FromAddress));
                    break;

                case EmailSortBy.FromAddressDescending:
                    this.Sort((x, y) => y.FromAddress.CompareTo(x.FromAddress));
                    break;
                }
            }

            if (Active != null)
            {
                this.RemoveAll(x => x.Active != (bool)Active);
            }

            if (EmailType != null)
            {
                this.RemoveAll(x => x.EmailType != (Config.EmailType)EmailType);
            }
            TotalCount = this.Count;
            if (RecsPerPage != null && this.Count > RecsPerPage)
            {
                if (Page == null)
                {
                    Page = 1;
                }
                Pages = (int)Math.Ceiling((decimal)this.Count / (decimal)RecsPerPage);
                int startRecord = (int)RecsPerPage * ((int)Page - 1);
                int endRecord   = startRecord + (int)RecsPerPage;
                if (endRecord < this.Count)
                {
                    this.RemoveRange(endRecord, this.Count - endRecord);
                }
                if (startRecord > 0)
                {
                    this.RemoveRange(0, startRecord);
                }
            }
            else
            {
                Pages = 1;
            }
        }