public async Task <long> createCase(string patientId, string clinicRecId, int caseType, string caseId, string caseNumber) { try { CaseRepository caseRepo = new CaseRepository(); //string caseNumber = ""; if (!string.IsNullOrEmpty(caseId)) { //QueryExpression query = new QueryExpression("incident"); //FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And); //childFilter.AddCondition("incidentid", ConditionOperator.Equal, new Guid(caseId)); //query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); //LinkEntity entityTypeDetails = new LinkEntity(xrm.Incident.EntityLogicalName, xrm.Contact.EntityLogicalName, "customerid", "contactid", JoinOperator.Inner); //entityTypeDetails.EntityAlias = "contact"; //entityTypeDetails.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_axrefrecid"); //query.LinkEntities.Add(entityTypeDetails); //SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); //EntityCollection entitycollection = entityRepository.GetEntityCollection(query); //if(entitycollection != null && entitycollection.Entities != null && entitycollection.Entities.Count > 0) //{ // if (entitycollection.Entities[0].Attributes.Contains("contact.mzk_axrefrecid")) // { // patientRecId = Convert.ToInt64((entitycollection.Entities[0]["contact.mzk_axrefrecid"] as AliasedValue).Value); // } // if (entitycollection.Entities[0].Attributes.Contains("mzk_casetype")) // { // caseType = Convert.ToInt32((entitycollection.Entities[0]["mzk_casetype"] as OptionSetValue).Value); // } // if (entitycollection.Entities[0].Attributes.Contains("ticketnumber")) // { // caseNumber = (entitycollection.Entities[0]["ticketnumber"]).ToString(); // } //} } long patientRecId = 0; Decimal decID; if (!string.IsNullOrEmpty(patientId)) { decID = Convert.ToDecimal(patientId); patientRecId = Convert.ToInt64(decID); } long caseRecId = caseRepo.createCase(patientRecId, Convert.ToInt64(clinicRecId), (HMCaseType)caseType, caseId, caseNumber); //Helper.Files.SaveToCSV(string.Format("{0}, {1}, {2}, {3}, {4}", caseRecId, patientRecId, Convert.ToInt64(clinicRecId), (HMCaseType)caseType, caseId), "test", DateTime.Now, DateTime.Now); return(caseRecId); } catch (Exception ex) { // Helper.Files.SaveToCSV(ex.Message, "test", DateTime.Now, DateTime.Now); throw ex; } }