/// <summary>
        /// Receives search criteria parameters (key/value pair) and returns a list of matching Subscribers
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Dtos.NotificationResults SendNotification(Dtos.NotificationInput input)
        {
            Logger.ErrorFormat("CH000:START5a1");
            Dtos.NotificationResults returnResults = new Dtos.NotificationResults();
            returnResults.ResponseMessage = String.Empty;
            List<string> recipients = new List<string>();
            List<CompanyConfig> companyConfig = new List<CompanyConfig>();
            try
            {
                Logger.ErrorFormat("CH000:START5a2");
                companyConfig = _companyConfigRepository.GetCompanyConfigurations(input.CompanyId);
                Logger.ErrorFormat("CH000:START5a3");

                try
                {
                    // Find your Account Sid and Auth Token at twilio.com/user/account 
                    string AccountSid = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:AccountSid"])).Value != null
                        ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:AccountSid"])).Value : "";
                    string AuthToken = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:AuthToken"])).Value != null
                        ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:AuthToken"])).Value : "";
                    var twilio = new TwilioRestClient(AccountSid, AuthToken);
                    string statusCallback = "";

                    string isActive = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:IsActive"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_Twilio:IsActive"])).Value
                    : "false";
                    if (isActive == "true")
                    {
                        //var response = twilio.SendMessage("+17209999740", input.EmailTo, input.EmailMessage, null, statusCallback);
                        twilio.SendMessage("+17209999740", input.EmailTo, input.EmailMessage, string.Empty, null);
                    }

                    returnResults.ResponseMessage = "Text Message Send Successful";

                    return returnResults;
                }
                catch (System.Exception exc)
                {
                    Logger.ErrorFormat("CH000", String.Format("CH000:{0}---->{1}", exc.Message, exc.StackTrace));
                    returnResults.ResponseMessage = exc.InnerException.Message;
                    return returnResults;
                }

            }
            catch (System.Exception exc)
            {
                Logger.ErrorFormat("CH000", String.Format("CH000:{0}---->{1}", exc.Message, exc.StackTrace));
                returnResults.ResponseMessage = exc.InnerException.Message;
                return returnResults;
            }
        }
 public NotificationResults SendEmail(NotificationInput input)
 {
     CreditsHero.Messaging.Dtos.NotificationResults results = new CreditsHero.Messaging.Dtos.NotificationResults();
     return (CreditsHero.Messaging.Dtos.NotificationResults)_creditsHeroConnect.CallCreditsHeroService<CreditsHero.Messaging.Dtos.NotificationResults>(results, input,
         "api/services/app/Notification/SendEmailNotification");
 }
        public Dtos.NotificationResults SendEmailNotification(Dtos.NotificationInput input)
        {
            Dtos.NotificationResults returnResults = new Dtos.NotificationResults();
            List<string> recipients = new List<string>();

            var companyConfig = _companyConfigRepository.GetCompanyConfigurations(input.CompanyId);

            if (input.EmailTo == null)
            {
                string emailTo = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:AdminEmailAddress"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:AdminEmailAddress"])).Value
                    : "*****@*****.**";
                recipients.Add(emailTo);
                //string emailTo = "*****@*****.**";
            }
            else
            {
                recipients.Add(input.EmailTo);
            }

            if (input.EmailFrom == null)
            {
                string emailFrom = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailReply"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailReply"])).Value
                    : "*****@*****.**";
                input.EmailFrom = emailFrom;
            }

            try
            {
                var message = new SendGridMessage();
                message.From = new MailAddress(input.EmailFrom);

                message.AddTo(recipients);
                message.Subject = input.EmailSubject;

                if (input.NotificationType == Messaging.NotificationTypes.Request.ToString("G")){
                    message.Html = String.Format(companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailRequestMessageTemplate"])).Value, input.SubscriberCriteria.CriteriaValues.Name, input.Request.Comment);
                }
                else {
                    message.Html = input.EmailMessage;
                }

                if (input.EmailTo == null)
                {
                    string emailTo = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:Username"])).Value != null
                        ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:AdminEmailAddress"])).Value
                        : "*****@*****.**";
                    recipients.Add(emailTo);
                }
                else
                {
                    recipients.Add(input.EmailTo);
                }

                var username = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:Username"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:Username"])).Value : "";
                var pwd = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:Password"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:Password"])).Value : "";
                var credentials = new System.Net.NetworkCredential(username, pwd);
                var transportWeb = new Web(credentials);

                try
                {
                    string isActive = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value != null
                    ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value
                    : "false";
                    if (isActive == "true")
                    {
                        var response = transportWeb.DeliverAsync(message);
                    }
                    returnResults.ResponseMessage = "Email submitted.  Thankyou!";
                    return returnResults;
                }
                catch(System.Exception exc)
                {
                    returnResults.ResponseMessage = exc.Message;
                    Logger.ErrorFormat("CH000", exc.StackTrace);
                    return returnResults;
                }
            }
            catch (System.Exception exc)
            {
                Logger.ErrorFormat("CH000", String.Format("CH000:{0}---->{1}", exc.Message, exc.StackTrace));
                returnResults.ResponseMessage = exc.InnerException.Message;
                return returnResults;
            }

        }
 public NotificationResults SendEmail(NotificationInput input)
 {
     CreditsHero.Messaging.Dtos.NotificationResults results = new CreditsHero.Messaging.Dtos.NotificationResults();
     return((CreditsHero.Messaging.Dtos.NotificationResults)_creditsHeroConnect.CallCreditsHeroService <CreditsHero.Messaging.Dtos.NotificationResults>(results, input,
                                                                                                                                                        "api/services/app/Notification/SendEmailNotification"));
 }