/// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            //If we don't know who you are then we won't allow the method to execute
            if (Common.FirebaseId == null && SamAccountName == null)
            {
                Response.error = Label.Get("error.authentication");
                return(false);
            }

            //Get a list of subscribers to the channel
            //If DTO.singleLangage is asserted then we only want users who prefer the associated langauge
            Subscription_BSO subBso = new Subscription_BSO();
            var chnSubs             = subBso.ChannelRead(Ado, DTO.LngIsoCode, DTO.ChnCode, DTO.singleLanguage);

            //Get the name of the requested channel
            var    channel = new Channel_BSO().Read(Ado, DTO.LngIsoCode, DTO.ChnCode).data.FirstOrDefault();
            string cName   = "";

            if (channel != null)
            {
                cName = channel.ChnName;
            }

            int           attemptCounter = 0;
            List <string> emailsNotSent  = new List <string>();

            foreach (var user in chnSubs)
            {
                if (String.IsNullOrEmpty(user.CcnEmail))
                {
                    continue;
                }
                attemptCounter++;
                using (eMail email = new eMail())
                {
                    try
                    {
                        email.Body    = DTO.EmailBody ?? Label.Get("email.subscription.notification-body", DTO.LngIsoCode);
                        email.Subject = DTO.EmailSubject ?? Label.Get("email.subscription.notification-body", DTO.LngIsoCode);
                        string salutation = String.Format(Label.Get("email.salutation-informal", DTO.LngIsoCode), user.FullName);

                        email.To.Add(user.CcnEmail);
                        Log.Instance.Debug($"Send notification to {user.CcnEmail}");
                        if (!sendMail(email, String.Format(Label.Get("email.subscription.notification-title", DTO.LngIsoCode), cName), email.Subject, email.Body, salutation))
                        {
                            emailsNotSent.Add(user.CcnEmail);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Instance.Error("Error sending email " + ex.Message);
                        emailsNotSent.Add(user.CcnEmail);
                    }
                }
            }
            Response.data = emailsNotSent;
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            Channel_BSO cBso = new Channel_BSO();


            var response = cBso.Read(Ado, DTO.LngIsoCode, DTO.ChnCode);

            if (response.hasData)
            {
                Response.data = response.data;
                return(true);
            }

            return(false);
        }