예제 #1
0
        private void createCampaignActivitySMS(Entity entity, string authentication, IOrganizationService service)
        {
            Guid          campaignActivityId = entity.Id;
            EmSmsCampaign smsCampaign;
            OrganizationServiceContext orgcontext = new OrganizationServiceContext(service);
            int sendingType = 1;

            try
            {
                if (entity.Contains("new_sendingtype"))
                {
                    sendingType = ((OptionSetValue)entity["new_sendingtype"]).Value;
                }

                var query = (from r in orgcontext.CreateQuery("campaignactivity")
                             where (Guid)r["activityid"] == campaignActivityId
                             select new
                {
                    campaign = r.Attributes.Contains("regardingobjectid") ? r["regardingobjectid"] : new EntityReference("campaign", Guid.Empty),
                    CampaignSubject = r.Attributes.Contains("subject") ? r["subject"] : string.Empty
                }).FirstOrDefault();

                if (query != null)
                {
                    smsCampaign                     = new EmSmsCampaign();
                    smsCampaign.CampaignID          = campaignActivityId.ToString().Replace("{", "").Replace("}", "").Replace("-", "").ToUpper();
                    smsCampaign.Name                = query.CampaignSubject.ToString();
                    smsCampaign.CampaignType        = EmSmsCampaignType.SingleShot;
                    smsCampaign.Originator          = "EUROMSG";
                    smsCampaign.Locked              = false;
                    smsCampaign.SmsMessage          = entity.Contains("new_smstext") ? entity["new_smstext"].ToString() : string.Empty;
                    smsCampaign.AlternateSmsMessage = "";
                    smsCampaign.UniqueSmsFlag       = true;

                    EmCampaignFuncRes emResponse = campaign.CreateSmsCampaign(authentication, ref smsCampaign);

                    if (emResponse.Code != "00")
                    {
                        throw new ApplicationException(emResponse.Code + " -- " + emResponse.Message + " -- " + emResponse.DetailedMessage);
                    }

                    LogoutEM(authentication);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.ToString());
            }
        }