コード例 #1
0
 public void SetTrashRecordProperties(JObject trashRecordDetails)
 {
     foreach (KeyValuePair <string, JToken> trashRecordDetail in trashRecordDetails)
     {
         string fieldAPIName = Convert.ToString(trashRecordDetail.Key);
         if (fieldAPIName.Equals("created_by") && trashRecordDetail.Value.Type != JTokenType.Null)
         {
             JObject  createdByObject = (JObject)trashRecordDetail.Value;
             ZCRMUser createdUser     = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), (string)createdByObject["name"]);
             trashRecord.CreatedBy = createdUser;
         }
         else if (fieldAPIName.Equals("deleted_by") && trashRecordDetail.Value.Type != JTokenType.Null)
         {
             JObject  modifiedByObject = (JObject)trashRecordDetail.Value;
             ZCRMUser DeletedByUser    = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]);
             trashRecord.DeletedBy = DeletedByUser;
         }
         else if (fieldAPIName.Equals("display_name"))
         {
             trashRecord.DisplayName = Convert.ToString(trashRecordDetail.Value);
         }
         else if (fieldAPIName.Equals("deleted_time"))
         {
             trashRecord.DeletedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(trashRecordDetail.Value));
         }
     }
 }
コード例 #2
0
        private ZCRMProfile GetZCRMProfile(JObject profileDetails)
        {
            ZCRMProfile profile = ZCRMProfile.GetInstance((long)profileDetails["id"], (string)profileDetails["name"]);

            profile.Category    = (bool)profileDetails["category"];
            profile.Description = (string)profileDetails["description"];
            profile.CreatedBy   = null;
            //TODO: Check with HasValues method;
            if (profileDetails["created_by"].Type != JTokenType.Null)
            {
                JObject  createdByObject = (JObject)profileDetails["created_by"];
                ZCRMUser createdBy       = ZCRMUser.GetInstance((long)createdByObject["id"], (string)createdByObject["name"]);
                profile.CreatedBy   = createdBy;
                profile.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(profileDetails["created_time"]));
            }
            profile.ModifiedBy = null;
            if (profileDetails["modified_by"].Type != JTokenType.Null)
            {
                JObject  modifiedByObject = (JObject)profileDetails["modified_by"];
                ZCRMUser modifiedBy       = ZCRMUser.GetInstance((long)modifiedByObject["id"], (string)modifiedByObject["name"]);
                profile.ModifiedBy   = modifiedBy;
                profile.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(profileDetails["modified_time"]));
            }

            return(profile);
        }
コード例 #3
0
        private ZCRMTerritory GetZCRMTerritory(JObject territory)
        {
            ZCRMTerritory territoryIns = ZCRMTerritory.GetInstance(Convert.ToInt64(territory["id"]));

            if (territory.ContainsKey("created_time") && territory["created_time"].Type != JTokenType.Null)
            {
                territoryIns.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(territory["created_time"]));
            }
            if (territory.ContainsKey("modified_time") && territory["modified_time"].Type != JTokenType.Null)
            {
                territoryIns.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(territory["modified_time"]));
            }
            if (territory.ContainsKey("manager") && territory["manager"].Type != JTokenType.Null)
            {
                if (territory["manager"] is JObject)
                {
                    JObject  managerByObject = (JObject)territory["created_by"];
                    ZCRMUser managerUser     = ZCRMUser.GetInstance((long)managerByObject["id"], (string)managerByObject["name"]);
                    territoryIns.Manager = managerUser;
                }
                if (territory["manager"].Type.ToString().Equals("Boolean"))
                {
                    territoryIns.IsManager = (bool)(territory["manager"]);
                }
            }
            if (territory.ContainsKey("parent_id") && territory["parent_id"].Type != JTokenType.Null)
            {
                territoryIns.ParentId = territory["parent_id"].ToString();
            }
            if (territory.ContainsKey("criteria") && territory["criteria"].Type != JTokenType.Null)
            {
                JObject jobj = (JObject)territory["criteria"];
                territoryIns.Criteria = SetZCRMCriteriaObject(jobj);
            }
            if (territory.ContainsKey("name") && territory["name"].Type != JTokenType.Null)
            {
                territoryIns.Name = territory["name"].ToString();
            }
            if (territory.ContainsKey("modified_by") && territory["modified_by"].Type != JTokenType.Null)
            {
                JObject  modifiedByObject = (JObject)territory["modified_by"];
                ZCRMUser modifiedUser     = ZCRMUser.GetInstance((long)modifiedByObject["id"], (string)modifiedByObject["name"]);
                territoryIns.ModifiedBy = modifiedUser;
            }
            if (territory.ContainsKey("description") && territory["description"].Type != JTokenType.Null)
            {
                territoryIns.Description = territory["description"].ToString();
            }
            if (territory.ContainsKey("created_by") && territory["created_by"].Type != JTokenType.Null)
            {
                JObject  createdByObject = (JObject)territory["created_by"];
                ZCRMUser createdUser     = ZCRMUser.GetInstance((long)createdByObject["id"], (string)createdByObject["name"]);
                territoryIns.CreatedBy = createdUser;
            }
            return(territoryIns);
        }
コード例 #4
0
        private ZCRMNote GetZCRMNote(JObject noteDetails, ZCRMNote note)
        {
            if (note == null)
            {
                note = ZCRMNote.GetInstance(parentRecord, Convert.ToInt64(noteDetails["id"]));
            }
            note.Id = Convert.ToInt64(noteDetails["id"]);
            if (noteDetails["Note_Title"] != null && noteDetails["Note_Title"].Type != JTokenType.Null)
            {
                note.Title = (string)noteDetails["Note_Title"];
            }
            if (noteDetails["Note_Content"] != null && noteDetails["Note_Content"].Type != JTokenType.Null)
            {
                note.Content = (string)noteDetails["Note_Content"];
            }
            JObject  createdByObject = (JObject)noteDetails["Created_By"];
            ZCRMUser createdBy       = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), (string)createdByObject["name"]);

            note.CreatedBy   = createdBy;
            note.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(noteDetails["Created_Time"]));

            JObject  modifiedByObject = (JObject)noteDetails["Modified_By"];
            ZCRMUser modifiedBy       = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]);

            note.ModifiedBy   = modifiedBy;
            note.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(noteDetails["Modified_Time"]));

            if (noteDetails["Owner"] != null && noteDetails["Owner"].Type != JTokenType.Null)
            {
                JObject  ownerObject = (JObject)noteDetails["Owner"];
                ZCRMUser owner       = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject["id"]), (string)ownerObject["name"]);
                note.NotesOwner = owner;
            }
            else
            {
                note.NotesOwner = createdBy;
            }
            if (noteDetails["$attachments"] != null && noteDetails["$attachments"].Type != JTokenType.Null)
            {
                JArray attachmentsArray = (JArray)noteDetails["$attachments"];
                foreach (JObject attachmentDetails in attachmentsArray)
                {
                    note.AddAttachment(GetZCRMAttachment(attachmentDetails));
                }
            }
            return(note);
        }
コード例 #5
0
ファイル: APIRequest.cs プロジェクト: jjarauz17/SysContabGRM
 private void SetHeaders(ref HttpWebRequest request)
 {
     foreach (KeyValuePair <string, string> keyValuePairs in RequestHeaders)
     {
         if (!string.IsNullOrEmpty(keyValuePairs.Value))
         {
             if (WebHeaderCollection.IsRestricted(keyValuePairs.Key))
             {
                 if (keyValuePairs.Key == "If-Modified-Since")
                 {
                     DateTime dateConversion = XmlConvert.ToDateTime(CommonUtil.removeEscaping(JsonConvert.SerializeObject(keyValuePairs.Value)), XmlDateTimeSerializationMode.Utc);
                     request.IfModifiedSince = dateConversion;
                 }
             }
             else
             {
                 request.Headers[keyValuePairs.Key] = keyValuePairs.Value;
             }
         }
     }
 }
コード例 #6
0
 private void SetTagProperties(ZCRMTag tag, JObject tagDetails)
 {
     foreach (KeyValuePair <string, JToken> token in tagDetails)
     {
         string fieldAPIName = token.Key;
         if (fieldAPIName.Equals("id"))
         {
             tag.Id = Convert.ToInt64(token.Value);
         }
         if (fieldAPIName.Equals("name"))
         {
             tag.Name = Convert.ToString(token.Value);
         }
         else if (fieldAPIName.Equals("created_by") && token.Value.Type != JTokenType.Null)
         {
             JObject  createdObject = (JObject)token.Value;
             ZCRMUser createdUser   = ZCRMUser.GetInstance(Convert.ToInt64(createdObject["id"]), (string)createdObject["name"]);
             tag.CreatedBy = createdUser;
         }
         else if (fieldAPIName.Equals("modified_by") && token.Value.Type != JTokenType.Null)
         {
             JObject  modifiedObject = (JObject)token.Value;
             ZCRMUser modifiedBy     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedObject["id"]), (string)modifiedObject["name"]);
             tag.ModifiedBy = modifiedBy;
         }
         else if (fieldAPIName.Equals("created_time"))
         {
             tag.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
         }
         else if (fieldAPIName.Equals("modified_time"))
         {
             tag.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
         }
         else if (fieldAPIName.Equals("count"))
         {
             tag.Count = Convert.ToInt32(token.Value);
         }
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        public void SetRecordProperties(JObject recordJSON, ZCRMRecord record)
        {
            foreach (KeyValuePair <string, JToken> token in recordJSON)
            {
                string fieldAPIName = token.Key;
                if (fieldAPIName.Equals("id"))
                {
                    record.EntityId = Convert.ToInt64(token.Value);
                }
                else if (fieldAPIName.Equals("Product_Details"))
                {
                    SetInventoryLineItems(token.Value);
                }
                else if (fieldAPIName.Equals("Participants"))
                {
                    SetParticipants(token.Value);
                }
                else if (fieldAPIName.Equals("Pricing_Details"))
                {
                    SetPriceDetails((JArray)token.Value);
                }
                else if (fieldAPIName.Equals("Created_By") && token.Value.Type != JTokenType.Null)
                {
                    JObject  createdObject = (JObject)token.Value;
                    ZCRMUser createdUser   = ZCRMUser.GetInstance(Convert.ToInt64(createdObject["id"]), (string)createdObject["name"]);
                    record.CreatedBy = createdUser;
                }
                else if (fieldAPIName.Equals("Modified_By") && token.Value.Type != JTokenType.Null)
                {
                    JObject  modifiedObject = (JObject)token.Value;
                    ZCRMUser modifiedBy     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedObject["id"]), (string)modifiedObject["name"]);
                    record.ModifiedBy = modifiedBy;
                }
                else if (fieldAPIName.Equals("Created_Time"))
                {
                    record.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
                }
                else if (fieldAPIName.Equals("Modified_Time"))
                {
                    record.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
                }
                else if (fieldAPIName.Equals("Owner") && token.Value.Type != JTokenType.Null)
                {
                    JObject  ownerObject = (JObject)token.Value;
                    ZCRMUser ownerUser   = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject["id"]), (string)ownerObject["name"]);
                    record.Owner = ownerUser;
                }
                else if (fieldAPIName.Equals("Layout") && token.Value.Type != JTokenType.Null)
                {
                    JObject    layoutObject = (JObject)token.Value;
                    ZCRMLayout layout       = ZCRMLayout.GetInstance(Convert.ToInt64(layoutObject["id"]));
                    layout.Name = (string)layoutObject["name"];
                }
                else if (fieldAPIName.Equals("Handler") && token.Value.Type != JTokenType.Null)
                {
                    JObject  handlerObject = (JObject)token.Value;
                    ZCRMUser handler       = ZCRMUser.GetInstance(Convert.ToInt64(handlerObject["id"]), (string)handlerObject["name"]);
                    record.SetFieldValue(fieldAPIName, handler);
                }

                else if (fieldAPIName.Equals("Remind_At") && token.Value.Type != JTokenType.Null)
                {
                    if (token.Value is JObject)
                    {
                        JObject remindObject = (JObject)token.Value;
                        record.SetFieldValue(fieldAPIName, remindObject["ALARM"]);
                    }
                    else
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                }
                else if (fieldAPIName.Equals("Recurring_Activity") && token.Value.Type != JTokenType.Null)
                {
                    JObject recurringActivityObject = (JObject)token.Value;
                    record.SetFieldValue(fieldAPIName, recurringActivityObject["RRULE"]);
                }
                else if (fieldAPIName.Equals("$line_tax") && token.Value.Type != JTokenType.Null)
                {
                    JArray taxDetails = (JArray)token.Value;
                    foreach (JObject taxDetail in taxDetails)
                    {
                        ZCRMTax tax = ZCRMTax.GetInstance((string)taxDetail["name"]);
                        tax.Percentage = Convert.ToDouble(taxDetail["percentage"]);
                        tax.Value      = Convert.ToDouble(taxDetail["value"]);
                        record.AddTax(tax);
                    }
                }
                else if (fieldAPIName.Equals("Tax") && token.Value.Type != JTokenType.Null)
                {
                    var taxNames = token.Value;
                    foreach (string data in taxNames)
                    {
                        ZCRMTax tax = ZCRMTax.GetInstance(data);
                        record.AddTax(tax);
                    }
                }
                else if (fieldAPIName.Equals("tags") && token.Value.Type != JTokenType.Null)
                {
                    JArray        jsonArray = (JArray)token.Value;
                    List <string> tags      = new List <string>();
                    foreach (string tag in jsonArray)
                    {
                        tags.Add(tag);
                    }
                    record.TagNames = tags;
                }
                else if (fieldAPIName.Equals("Tag") && token.Value.Type != JTokenType.Null)
                {
                    JArray jsonArray = (JArray)token.Value;
                    foreach (JObject tag in jsonArray)
                    {
                        ZCRMTag tagIns = ZCRMTag.GetInstance(Convert.ToInt64(tag.GetValue("id")));
                        tagIns.Name = tag.GetValue("name").ToString();
                        record.Tags.Add(tagIns);
                    }
                }
                else if (fieldAPIName.StartsWith("$", StringComparison.CurrentCulture))
                {
                    fieldAPIName = fieldAPIName.TrimStart('\\', '$');
                    if (APIConstants.PROPERTIES_AS_FILEDS.Contains(fieldAPIName))
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                    else
                    {
                        record.SetProperty(fieldAPIName, token.Value);
                    }
                }
                else if (token.Value is JObject)
                {
                    JObject    lookupDetails = (JObject)token.Value;
                    ZCRMRecord lookupRecord  = ZCRMRecord.GetInstance(fieldAPIName, Convert.ToInt64(lookupDetails["id"]));
                    lookupRecord.LookupLabel = (string)lookupDetails["name"];
                    record.SetFieldValue(fieldAPIName, lookupRecord);
                }
                else if (token.Value is JArray)
                {
                    JArray        jsonArray = (JArray)token.Value;
                    List <object> values    = new List <object>();

                    foreach (Object obj in jsonArray)
                    {
                        if (obj is JObject)
                        {
                            values.Add((JObject)obj);
                        }
                        else
                        {
                            values.Add(obj);
                        }
                    }
                    record.SetFieldValue(fieldAPIName, values);
                }
                else
                {
                    if (token.Value.Type.ToString().Equals("Date"))
                    {
                        record.SetFieldValue(fieldAPIName, CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value)));
                    }
                    else
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                }
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        private ZCRMUser GetZCRMUser(JObject userDetails)
        {
            ZCRMUser user = ZCRMUser.GetInstance((long)userDetails["id"], (string)userDetails["full_name"]);

            user.EmailId   = (string)userDetails["email"];
            user.FirstName = (string)userDetails["first_name"];
            user.LastName  = (string)userDetails["last_name"];
            user.Language  = (string)userDetails["language"];
            user.Mobile    = (string)userDetails["mobile"];
            user.Status    = (string)userDetails["status"];
            user.ZuId      = (long?)userDetails["zuid"];
            if (userDetails.ContainsKey("profile"))
            {
                JObject     profileObject = (JObject)userDetails["profile"];
                ZCRMProfile profile       = ZCRMProfile.GetInstance((long)profileObject["id"], (string)profileObject["name"]);
                user.Profile = profile;
            }
            if (userDetails.ContainsKey("role"))
            {
                JObject  roleObject = (JObject)userDetails["role"];
                ZCRMRole role       = ZCRMRole.GetInstance((long)roleObject["id"], (string)roleObject["name"]);
                user.Role = role;
            }

            user.Alias            = (string)userDetails["alias"];
            user.City             = (string)userDetails["city"];
            user.Confirm          = (bool)userDetails["confirm"];
            user.CountryLocale    = (string)userDetails["country_locale"];
            user.DateFormat       = (string)userDetails["date_format"];
            user.TimeFormat       = (string)userDetails["time_format"];
            user.DateOfBirth      = (string)userDetails["dob"];
            user.Country          = (string)userDetails["country"];
            user.Fax              = (string)userDetails["fax"];
            user.Locale           = (string)userDetails["locale"];
            user.NameFormat       = (string)userDetails["name_format"];
            user.Website          = (string)userDetails["website"];
            user.TimeZone         = (string)userDetails["time_zone"];
            user.Street           = (string)userDetails["street"];
            user.State            = (string)userDetails["state"];
            user.MicrosoftAppUser = (bool)userDetails["microsoft"];
            user.Phone            = (string)userDetails["phone"];
            if (userDetails.ContainsKey("created_by") && userDetails["created_by"].Type != JTokenType.Null)
            {
                JObject  createdByObject = (JObject)userDetails["created_by"];
                ZCRMUser createdUser     = ZCRMUser.GetInstance((long)createdByObject["id"], (string)createdByObject["name"]);
                user.CreatedBy   = createdUser;
                user.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(userDetails["created_time"]));
            }
            if (userDetails.ContainsKey("Modified_By") && userDetails["Modified_By"].Type != JTokenType.Null)
            {
                JObject  modifiedByObject = (JObject)userDetails["Modified_By"];
                ZCRMUser modifiedByUser   = ZCRMUser.GetInstance((long)modifiedByObject["id"], (string)modifiedByObject["name"]);
                user.ModifiedBy   = modifiedByUser;
                user.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(userDetails["Modified_Time"]));
            }
            if (userDetails.ContainsKey("Reporting_To") && userDetails["Reporting_To"].Type != JTokenType.Null)
            {
                JObject  reportingToObject = (JObject)userDetails["Reporting_To"];
                ZCRMUser reportingTo       = ZCRMUser.GetInstance((long)reportingToObject["id"], (string)reportingToObject["name"]);
                user.ReportingTo = reportingTo;
            }
            if (userDetails.ContainsKey("signature") && userDetails["signature"].Type != JTokenType.Null)
            {
                user.Signature = (string)userDetails["signature"];
            }
            if (userDetails.ContainsKey("number") && userDetails["number"].Type != JTokenType.Null)
            {
                user.Number = (int)userDetails["number"];
            }
            if (userDetails.ContainsKey("offset") && userDetails["offset"].Type != JTokenType.Null)
            {
                user.OffSet = (long)userDetails["offset"];
            }
            if (userDetails.ContainsKey("customize_info") && userDetails["customize_info"].Type != JTokenType.Null)
            {
                user.CustomizeInfo = GetZCRMUserCustomizeInfo((JObject)userDetails["customize_info"]);
            }
            if (userDetails.ContainsKey("personal_account") && userDetails["personal_account"].Type != JTokenType.Null)
            {
                user.IsPersonalAccount = (bool)userDetails["personal_account"];
            }
            if (userDetails.ContainsKey("default_tab_group") && userDetails["default_tab_group"].Type != JTokenType.Null)
            {
                user.DefaultTabGroup = (string)userDetails["default_tab_group"];
            }
            if (userDetails.ContainsKey("theme") && userDetails["theme"].Type != JTokenType.Null)
            {
                user.Theme = GetZCRMUserTheme((JObject)userDetails["theme"]);
            }
            if (userDetails.ContainsKey("zip") && userDetails["zip"].Type != JTokenType.Null)
            {
                user.Zip = (string)userDetails["zip"];
            }
            if (userDetails.ContainsKey("decimal_separator") && userDetails["decimal_separator"].Type != JTokenType.Null)
            {
                user.DecimalSeparator = (string)userDetails["decimal_separator"];
            }
            if (userDetails.ContainsKey("territories") && userDetails["territories"].Type != JTokenType.Null)
            {
                JArray jsonArray = (JArray)userDetails["territories"];
                List <ZCRMTerritory> territories = new List <ZCRMTerritory>();
                foreach (JObject territory in jsonArray)
                {
                    territories.Add(GetZCRMTerritory(territory));
                }
                user.Territories = territories;
            }
            if (userDetails.ContainsKey("Isonline") && userDetails["Isonline"].Type != JTokenType.Null)
            {
                user.IsOnline = (bool)userDetails["Isonline"];
            }
            if (userDetails.ContainsKey("Currency") && userDetails["Currency"].Type != JTokenType.Null)
            {
                user.Currency = (string)userDetails["Currency"];
            }
            foreach (KeyValuePair <string, JToken> token in userDetails)
            {
                if (!ZCRMUser.defaultKeys.Contains(token.Key))
                {
                    user.SetFieldValue(token.Key, (object)token.Value);
                }
            }
            return(user);
        }
コード例 #11
0
        private ZCRMAttachment GetZCRMAttachment(JObject attachmentDetails)
        {
            ZCRMAttachment attachment = ZCRMAttachment.GetInstance(parentRecord, Convert.ToInt64(attachmentDetails["id"]));
            string         fileName   = (string)attachmentDetails["File_Name"];

            if (fileName != null)
            {
                attachment.FileName = fileName;
                attachment.FileType = fileName.Substring(fileName.LastIndexOf('.') + 1);
            }
            if (attachmentDetails.ContainsKey("Size"))
            {
                attachment.Size = Convert.ToInt64(attachmentDetails["Size"]);
            }
            if (attachmentDetails.ContainsKey("Created_By") && attachmentDetails["Created_By"].Type != JTokenType.Null)
            {
                JObject  createdByObject = (JObject)attachmentDetails["Created_By"];
                ZCRMUser createdBy       = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), (string)createdByObject["name"]);
                attachment.CreatedBy   = createdBy;
                attachment.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(attachmentDetails["Created_Time"]));

                if (attachmentDetails["Owner"] != null && attachmentDetails["Owner"].Type != JTokenType.Null)
                {
                    JObject  ownerObject = (JObject)attachmentDetails["Owner"];
                    ZCRMUser owner       = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject["id"]), (string)ownerObject["name"]);
                    attachment.Owner = owner;
                }
                else
                {
                    attachment.Owner = createdBy;
                }
            }
            if (attachmentDetails.ContainsKey("Modified_By") && attachmentDetails["Modified_By"].Type != JTokenType.Null)
            {
                JObject  modifiedByObject = (JObject)attachmentDetails["Modified_By"];
                ZCRMUser modifiedBy       = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]);
                attachment.ModifiedBy   = modifiedBy;
                attachment.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(attachmentDetails["Modified_Time"]));
            }

            if (attachmentDetails.ContainsKey("$editable"))
            {
                if (attachmentDetails["$editable"] != null)
                {
                    attachment.Editable = Convert.ToBoolean(attachmentDetails["$editable"]);
                }
            }
            if (attachmentDetails.ContainsKey("$file_id"))
            {
                if (attachmentDetails["$file_id"] != null)
                {
                    attachment.FieldId = Convert.ToString(attachmentDetails["$file_id"]);
                }
            }
            if (attachmentDetails.ContainsKey("$type"))
            {
                if (attachmentDetails["$type"] != null)
                {
                    attachment.Type = Convert.ToString(attachmentDetails["$type"]);
                }
            }
            if (attachmentDetails.ContainsKey("$se_module"))
            {
                if (attachmentDetails["$se_module"] != null)
                {
                    attachment.Se_module = Convert.ToString(attachmentDetails["$se_module"]);
                }
            }
            if (attachmentDetails.ContainsKey("$link_url"))
            {
                if (attachmentDetails["$link_url"] != null)
                {
                    attachment.Link_url = Convert.ToString(attachmentDetails["$link_url"]);
                }
            }

            return(attachment);
        }