private ZCRMModule GetZCRMModule(JObject moduleDetails) { try { ZCRMModule module = ZCRMModule.GetInstance((string)moduleDetails["api_name"]); module.Id = Convert.ToInt64(moduleDetails["id"]); module.SystemName = (string)moduleDetails["module_name"]; module.SingularLabel = (string)moduleDetails["singular_label"]; module.PluralLabel = (string)moduleDetails["plural_label"]; module.Creatable = (bool)moduleDetails["creatable"]; module.Viewable = (bool)moduleDetails["viewable"]; module.Editable = (bool)moduleDetails["editable"]; module.Convertable = (bool)moduleDetails["convertable"]; module.Deletable = (bool)moduleDetails["deletable"]; module.CustomModule = (bool)(moduleDetails["generated_type"].ToString().Equals("custom")); module.ApiSupported = (bool)(moduleDetails["api_supported"]); JArray accessibleProfilesArray = (JArray)moduleDetails["profiles"]; foreach (JObject accessibleProfiles in accessibleProfilesArray) { ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles["id"]), (string)accessibleProfiles["name"]); module.AddAccessibleProfile(profile); } if (moduleDetails["modified_by"].HasValues) { JObject modifiedByObject = (JObject)moduleDetails["modified_by"]; ZCRMUser modifiedUser = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]); module.ModifiedBy = modifiedUser; module.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(moduleDetails["modified_time"])); } if (moduleDetails.ContainsKey("related_lists") && moduleDetails["related_lists"].Type != JTokenType.Null) { List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>(); JArray relatedListsArray = (JArray)moduleDetails["related_lists"]; foreach (JObject relatedListDetails in relatedListsArray) { ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, (string)relatedListDetails["api_name"]); SetRelatedListProperties(relatedList, relatedListDetails); relatedLists.Add(relatedList); } module.RelatedLists = relatedLists; } if (moduleDetails.ContainsKey("business_card_fields") && moduleDetails.Type != JTokenType.Null) { List <string> bcFields = new List <string>(); JArray bcFieldsArray = (JArray)moduleDetails["business_card_fields"]; foreach (JObject bcField in bcFieldsArray) { bcFields.Add(bcField.ToString()); } module.BussinessCardFields = bcFields; } if (moduleDetails.ContainsKey("layouts")) { module.Layouts = ModuleAPIHandler.GetInstance(module).GetAllLayouts(moduleDetails); } return(module); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
private ZCRMLayout GetZCRMLayout(JObject layoutDetails) { ZCRMLayout layout = ZCRMLayout.GetInstance(Convert.ToInt64(layoutDetails["id"])); layout.Name = Convert.ToString(layoutDetails["name"]); layout.Visible = Convert.ToBoolean(layoutDetails["visible"]); layout.Status = Convert.ToInt32(layoutDetails["status"]); if (layoutDetails["created_by"].HasValues) { JObject createdByObject = (JObject)layoutDetails["created_by"]; ZCRMUser createdUser = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), Convert.ToString(createdByObject["name"])); layout.CreatedBy = createdUser; layout.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(layoutDetails["created_time"])); } if (layoutDetails["modified_by"].HasValues) { JObject modifiedByObject = (JObject)layoutDetails["modified_by"]; ZCRMUser modifiedUser = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), Convert.ToString(modifiedByObject["name"])); layout.ModifiedBy = modifiedUser; layout.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(layoutDetails["modified_time"])); } JArray accessibleProfilesArray = (JArray)layoutDetails["profiles"]; foreach (JObject profileObject in accessibleProfilesArray) { ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(profileObject["id"]), Convert.ToString(profileObject["name"])); if (profileObject.ContainsKey("default") && profileObject["default"].Type != JTokenType.Null) { profile.IsDefault = Convert.ToBoolean(profileObject["default"]); } layout.AddAccessibleProfiles(profile); } layout.Sections = GetAllSectionsofLayout(layoutDetails); if (layoutDetails.ContainsKey("convert_mapping") && layoutDetails["convert_mapping"].Type != JTokenType.Null) { List <string> convertModules = new List <string>() { "Contacts", "Deals", "Accounts" }; Dictionary <string, ZCRMLeadConvertMapping> convertMapDic = new Dictionary <string, ZCRMLeadConvertMapping>(); foreach (string convertModule in convertModules) { if (((JObject)layoutDetails["convert_mapping"]).ContainsKey(convertModule) && ((JObject)layoutDetails["convert_mapping"])[convertModule].Type != JTokenType.Null) { JObject contactsMap = (JObject)layoutDetails["convert_mapping"][convertModule]; ZCRMLeadConvertMapping convertMapIns = ZCRMLeadConvertMapping.GetInstance(contactsMap["name"].ToString(), Convert.ToInt64(contactsMap["id"])); if (contactsMap.ContainsKey("fields") && contactsMap["fields"].Type != JTokenType.Null) { List <ZCRMLeadConvertMappingField> ConvertMappingFields = new List <ZCRMLeadConvertMappingField>(); JArray fields = (JArray)contactsMap["fields"]; foreach (JObject field in fields) { ZCRMLeadConvertMappingField convertMappingFieldIns = ZCRMLeadConvertMappingField.GetInstance(field["api_name"].ToString(), Convert.ToInt64(field["id"])); convertMappingFieldIns.FieldLabel = field["field_label"].ToString(); convertMappingFieldIns.Required = Convert.ToBoolean(field["required"]); ConvertMappingFields.Add(convertMappingFieldIns); } convertMapIns.Fields = ConvertMappingFields; } convertMapDic.Add(convertModule, convertMapIns); } } layout.ConvertMapping = convertMapDic; } return(layout); }