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);
        }
示例#2
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);
     }
 }
        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);
        }
示例#4
0
 /// <summary>
 /// To add the accessible profile of the module by passing ZCRMProfile class instance.
 /// </summary>
 /// <param name="profile">ZCRMProfile class instance</param>
 public void AddAccessibleProfile(ZCRMProfile profile)
 {
     AccessibleProfiles.Add(profile);
 }
示例#5
0
        /** To get All Users */
        public void GetAllUsers()
        {
            ZCRMRestClient             restClient = ZCRMRestClient.GetInstance();
            BulkAPIResponse <ZCRMUser> response   = restClient.GetOrganizationInstance().GetAllUsers();
            List <ZCRMUser>            allUsers   = response.BulkData; // users - list of ZCRMUser instances

            foreach (ZCRMUser user in allUsers)
            {
                Console.WriteLine(user.Country);
                ZCRMRole Role = user.Role;
                if (Role != null)
                {
                    Console.WriteLine(Role.Id);
                    Console.WriteLine(Role.Name);
                }
                if (user.CustomizeInfo != null)
                {
                    ZCRMUserCustomizeInfo customizeInfo = user.CustomizeInfo;
                    Console.WriteLine(customizeInfo.NotesDesc);
                    Console.WriteLine(customizeInfo.IsToShowRightPanel);
                    Console.WriteLine(customizeInfo.IsBcView);
                    Console.WriteLine(customizeInfo.IsToShowHome);
                    Console.WriteLine(customizeInfo.IsToShowDetailView);
                    Console.WriteLine(customizeInfo.UnpinRecentItem);
                }
                Console.WriteLine(user.City);
                Console.WriteLine(user.Signature);
                Console.WriteLine(user.NameFormat);
                Console.WriteLine(user.Language);
                Console.WriteLine(user.Locale);
                Console.WriteLine(user.MicrosoftAppUser);
                Console.WriteLine(user.IsPersonalAccount);
                Console.WriteLine(user.IsOnline);
                Console.WriteLine(user.DefaultTabGroup);
                ZCRMUser ModifiedBy = user.ModifiedBy;
                if (ModifiedBy != null)
                {
                    Console.WriteLine(ModifiedBy.Id);
                    Console.WriteLine(ModifiedBy.FullName);
                }
                Console.WriteLine(user.Number);
                Console.WriteLine(user.Street);
                Console.WriteLine(user.Alias);
                if (user.Theme != null)
                {
                    ZCRMUserTheme theme = user.Theme;
                    Console.WriteLine(theme.NormalTabFontColor);
                    Console.WriteLine(theme.NormalTabBackground);
                    Console.WriteLine(theme.SelectedTabFontColor);
                    Console.WriteLine(theme.SelectedTabBackground);
                    Console.WriteLine(theme.New_background);
                    Console.WriteLine(theme.Background);
                    Console.WriteLine(theme.Screen);
                    Console.WriteLine(theme.Type);
                }
                Console.WriteLine(user.Id);
                Console.WriteLine(user.State);
                Console.WriteLine(user.Fax);
                Console.WriteLine(user.CountryLocale);
                Console.WriteLine(user.FirstName);
                Console.WriteLine(user.EmailId);
                ZCRMUser ReportingTo = user.ReportingTo;
                if (ReportingTo != null)
                {
                    Console.WriteLine(ReportingTo.Id);
                    Console.WriteLine(ReportingTo.FullName);
                }
                Console.WriteLine(user.Zip);
                Console.WriteLine(user.DecimalSeparator);
                Console.WriteLine(user.CreatedTime);
                Console.WriteLine(user.ModifiedTime);
                Console.WriteLine(user.Website);
                Console.WriteLine(user.TimeFormat);
                Console.WriteLine(user.OffSet);
                ZCRMProfile Profile = user.Profile;
                if (Profile != null)
                {
                    Console.WriteLine(Profile.Id);
                    Console.WriteLine(Profile.Name);
                }
                Console.WriteLine(user.Mobile);
                Console.WriteLine(user.LastName);
                Console.WriteLine(user.TimeZone);
                ZCRMUser CreatedBy = user.CreatedBy;
                if (CreatedBy != null)
                {
                    Console.WriteLine(CreatedBy.Id);
                    Console.WriteLine(CreatedBy.FullName);
                }
                Console.WriteLine(user.ZuId);
                Console.WriteLine(user.Confirm);
                Console.WriteLine(user.FullName);
                if (user.Territories != null && user.Territories.Count > 0)
                {
                    foreach (ZCRMTerritory territory in user.Territories)
                    {
                        Console.WriteLine(territory.IsManager);
                        Console.WriteLine(territory.Name);
                        Console.WriteLine(territory.Id);
                    }
                }
                Console.WriteLine(user.Phone);
                Console.WriteLine(user.DateOfBirth);
                Console.WriteLine(user.DateFormat);
                Console.WriteLine(user.Status);
            }
        }
        private JObject ConstructJSONForUser(ZCRMUser user)
        {
            JObject  userJSON = new JObject();
            ZCRMRole role     = user.Role;

            if (role != null)
            {
                userJSON["role"] = role.Id.ToString();
            }
            ZCRMProfile profile = user.Profile;

            if (profile != null)
            {
                userJSON["profile"] = profile.Id.ToString();
            }
            if (user.Country != null)
            {
                userJSON["country"] = user.Country;
            }
            if (user.City != null)
            {
                userJSON["city"] = user.City;
            }
            if (user.Signature != null)
            {
                userJSON["signature"] = user.Signature;
            }
            if (user.NameFormat != null)
            {
                userJSON["name_format"] = user.NameFormat;
            }
            if (user.Language != null)
            {
                userJSON["language"] = user.Language;
            }
            if (user.Locale != null)
            {
                userJSON["locale"] = user.Locale;
            }
            if (user.DefaultTabGroup != null)
            {
                userJSON["default_tab_group"] = user.DefaultTabGroup;
            }
            if (user.Street != null)
            {
                userJSON["street"] = user.Street;
            }
            if (user.Alias != null)
            {
                userJSON["alias"] = user.Alias;
            }
            if (user.State != null)
            {
                userJSON["state"] = user.State;
            }
            if (user.CountryLocale != null)
            {
                userJSON["country_locale"] = user.CountryLocale;
            }
            if (user.Fax != null)
            {
                userJSON["fax"] = user.Fax;
            }
            if (user.FirstName != null)
            {
                userJSON["first_name"] = user.FirstName;
            }
            if (user.EmailId != null)
            {
                userJSON["email"] = user.EmailId;
            }
            if (user.Zip != null)
            {
                userJSON["zip"] = user.Zip;
            }
            if (user.DecimalSeparator != null)
            {
                userJSON["decimal_separator"] = user.DecimalSeparator;
            }
            if (user.Website != null)
            {
                userJSON["website"] = user.Website;
            }
            if (user.TimeFormat != null)
            {
                userJSON["time_format"] = user.TimeFormat;
            }
            if (user.Mobile != null)
            {
                userJSON["mobile"] = user.Mobile;
            }
            if (user.LastName != null)
            {
                userJSON["last_name"] = user.LastName;
            }
            if (user.TimeZone != null)
            {
                userJSON["time_zone"] = user.TimeZone;
            }
            if (user.Phone != null)
            {
                userJSON["phone"] = user.Phone;
            }
            if (user.DateOfBirth != null)
            {
                userJSON["dob"] = user.DateOfBirth;
            }
            if (user.DateFormat != null)
            {
                userJSON["date_format"] = user.DateFormat;
            }
            if (user.Status != null)
            {
                userJSON["status"] = user.Status;
            }

            foreach (KeyValuePair <string, object> token in user.Data)
            {
                userJSON[token.Key] = JToken.FromObject(token.Value);
            }

            userJSON["personal_account"] = user.IsPersonalAccount;
            return(userJSON);
        }
        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);
        }