Ejemplo n.º 1
0
        public List <QueuedEmail> SelectAll()
        {
            List <QueuedEmail> qeuedEmails = new List <QueuedEmail>();
            const string       q           =
                @"SELECT * FROM dbo.QueuedEmails where Deleted <> 1";

            using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
                    using (OpenCbsReader r = c.ExecuteReader())
                    {
                        if (r.Empty)
                        {
                            return(qeuedEmails);
                        }

                        while (r.Read())
                        {
                            var queuedEmail = new QueuedEmail
                            {
                                Id             = r.GetInt("Id"),
                                Priority       = r.GetInt("Priority"),
                                From           = r.GetString("From"),
                                FromName       = r.GetString("FromName"),
                                To             = r.GetString("To"),
                                ToName         = r.GetString("ToName"),
                                ReplyTo        = r.GetString("ReplyTo"),
                                ReplyToName    = r.GetString("ReplyToName"),
                                CC             = r.GetString("CC"),
                                Bcc            = r.GetString("Bcc"),
                                Body           = r.GetString("Body"),
                                CreatedOnUtc   = r.GetDateTime("CreatedOnUtc"),
                                SentOnUtc      = r.GetNullDateTime("SentOnUtc"),
                                EmailAccountId = r.GetInt("EmailAccountId"),
                                SentTries      = r.GetInt("SentTries"),
                                Subject        = r.GetString("Subject"),
                                Deleted        = r.GetBool("Deleted"),
                            };

                            if (queuedEmail.EmailAccountId > 0)
                            {
                                EmailAccountManager _emailAccountManager = new EmailAccountManager(user);
                                queuedEmail.EmailAccount = _emailAccountManager.SelectById(queuedEmail.EmailAccountId);
                            }
                            qeuedEmails.Add(queuedEmail);
                        }
                    }
            return(qeuedEmails);
        }
        public MessageTemplate SelectByName(string name)
        {
            string q =
                @"SELECT * FROM dbo.MessageTemplates WHERE Name LIKE '%{0}%' AND Deleted <> 1";

            q = string.Format(q, name);

            using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
                    using (OpenCbsReader r = c.ExecuteReader())
                    {
                        if (r.Empty)
                        {
                            return(null);
                        }
                        if (!r.Read())
                        {
                            return(null);
                        }
                        var messageTemplate = new MessageTemplate
                        {
                            Id   = r.GetInt("Id"),
                            Name = r.GetString("Name"),
                            BccEmailAddresses = r.GetString("BccEmailAddresses"),
                            Subject           = r.GetString("Subject"),
                            Body           = r.GetString("Body"),
                            EmailBody      = r.GetString("EmailBody"),
                            SendEmail      = r.GetNullBool("SendEmail"),
                            SendSMS        = r.GetNullBool("SendSMS"),
                            IsActive       = r.GetBool("IsActive"),
                            EmailAccountId = r.GetInt("EmailAccountId"),
                            IsDefault      = r.GetBool("IsDefault"),
                            Deleted        = r.GetBool("Deleted"),
                        };

                        if (messageTemplate.EmailAccountId > 0)
                        {
                            EmailAccountManager _emailAccountManager = new EmailAccountManager(user);
                            messageTemplate.EmailAccount = _emailAccountManager.SelectById(messageTemplate.EmailAccountId);
                        }

                        return(messageTemplate);
                    }
        }
        public List <MessageTemplate> SelectAll()
        {
            List <MessageTemplate> messageTemplates = new List <MessageTemplate>();
            const string           q =
                @"SELECT * FROM dbo.MessageTemplates where Deleted <> 1";

            using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
                    using (OpenCbsReader r = c.ExecuteReader())
                    {
                        if (r.Empty)
                        {
                            return(messageTemplates);
                        }

                        while (r.Read())
                        {
                            var messageTemplate = new MessageTemplate
                            {
                                Id   = r.GetInt("Id"),
                                Name = r.GetString("Name"),
                                BccEmailAddresses = r.GetString("BccEmailAddresses"),
                                Subject           = r.GetString("Subject"),
                                Body           = r.GetString("Body"),
                                EmailBody      = r.GetString("EmailBody"),
                                SendEmail      = r.GetNullBool("SendEmail"),
                                SendSMS        = r.GetNullBool("SendSMS"),
                                IsActive       = r.GetBool("IsActive"),
                                EmailAccountId = r.GetInt("EmailAccountId"),
                                IsDefault      = r.GetBool("IsDefault"),
                                Deleted        = r.GetBool("Deleted"),
                            };

                            if (messageTemplate.EmailAccountId > 0)
                            {
                                EmailAccountManager _emailAccountManager = new EmailAccountManager(user);
                                messageTemplate.EmailAccount = _emailAccountManager.SelectById(messageTemplate.EmailAccountId);
                            }
                            messageTemplates.Add(messageTemplate);
                        }
                    }
            return(messageTemplates);
        }