using System;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using System.Text;
using System.Threading.Tasks;
using Basic_plugin.CaseInfo;
namespace Basic_plugin
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService traceObj = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "e011_cases")
{
try
{
//IOrganizationService service = GetOrganization();
QueryExpression qetwo = new QueryExpression
{
EntityName = "e11_cas",
ColumnSet = new ColumnSet(true)
};
qetwo.Criteria.AddCondition("e011_caseid", ConditionOperator.Equal, "ADI00194");
EntityCollection ectwo = service.RetrieveMultiple(qetwo);
string caseid = ectwo.Entities[0].Attributes["e011_caseid"].ToString();
string companycode = ectwo.Entities[0].Attributes["e011_companycode"].ToString();
String weborderid = String.Empty;
if (ectwo.Entities[0].Contains("new_weborderidnew"))
{
weborderid = ((EntityReference)ectwo.Entities[0].Attributes["new_weborderidnew"]).Name;
}
// string casecategoryid = ectwo.Entities[0].Attributes["e011_caseid"].ToString();
DateTime casedate = Convert.ToDateTime(ectwo.Entities[0].Attributes["createdon"].ToString());
//var nameRef = (Microsoft.Xrm.Sdk.EntityReference)ectwo.Entities[0].Attributes["new_weborderidnew"];
//var actualName = service.Retrieve(nameRef.LogicalName, nameRef.Id, new ColumnSet(true));
//string weborderid = actualName["new_name"].ToString();
// string websaleslineid = ectwo.Entities[0].Attributes["e011_caseid"].ToString();
// string state = ectwo.Entities[0].Attributes["e011_caseid"].ToString();
// string zipcode = ectwo.Entities[0].Attributes["e011_caseid"].ToString();
// string calltype = ectwo.Entities[0].Attributes["e011_calltype"].ToString();
CaseInfo.ACX_CaseTableQServiceClient Proxy = new CaseInfo.ACX_CaseTableQServiceClient();
CaseInfo.CallContext cnx = new CaseInfo.CallContext();
cnx.Company = "1100";
Proxy.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
Proxy.ClientCredentials.Windows.ClientCredential.Domain = "ad";
Proxy.ClientCredentials.Windows.ClientCredential.Password = "@42";
CaseInfo.AxdACX_CaseTableQ ObjCasetableQ = new CaseInfo.AxdACX_CaseTableQ();
CaseInfo.AxdEntity_Acx_CaseTable_1 objAxd = new CaseInfo.AxdEntity_Acx_CaseTable_1();
objAxd.CaseID = caseid;
objAxd.CaseDate = casedate;
objAxd.CaseCategoryId = "C0005";
objAxd.State = "DL";
objAxd.CaseSubType = CaseInfo.AxdEnum_Acx_CaseSubType.NDR;// ACX_CaseTableQ.AxdEnum_Acx_CaseSubType.COD ;
// objAxd.CaseSubTypeSpecified = true;
objAxd.CaseStatus = CaseInfo.AxdEnum_Acx_CaseStatus.Open;// ACX_CaseTableQ.AxdEnum_Acx_CaseSubType.COD ;
objAxd.CaseStatusSpecified = true;
objAxd.CaseType = CaseInfo.AxdEnum_Acx_CaseType.Inbound;// ACX_CaseTableQ.AxdEnum_Acx_CaseSubType.COD ;
// objAxd.CA = true;
objAxd.RefundPaymentMethod = CaseInfo.AxdEnum_ACX_RefundPaymentMethod.Cheque;// ACX_CaseTableQ.AxdEnum_Acx_CaseSubType.COD ;
objAxd.RefundPaymentMethodSpecified = true;
objAxd.CompanyCode = "11";
objAxd.RefWebOrderID = "11568224";
objAxd.RefWebSalesLineID = "ITEM1503489096289159290";
objAxd.Zipcode = "110035";
objAxd.CustomerCode = "D4Z7PBxSLwwHWUC";
objAxd.Address1 = "EFWE,keshavpuram,DL,IND";
ObjCasetableQ.Acx_CaseTable_1 = new CaseInfo.AxdEntity_Acx_CaseTable_1[1]
{
objAxd
};
CaseInfo.EntityKey[] ReturnKey = Proxy.create(cnx, ObjCasetableQ);
}
catch (Exception ex)
{
traceObj.Trace("Plugin Exception : {0}", ex.ToString());
traceObj.Trace("Plugin Ends With No Excepption");
}
}
}
}
}
This is my Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ACX_CaseTableQService" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://url"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ACX_CaseTableQService"
contract="CaseInfo.ACX_CaseTableQService" name="NetTcpBinding_ACX_CaseTableQService">
<identity>
<userPrincipalName value="administrator@AAIN.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>