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 = (string)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 = (string)profileDetails["modified_time"];
            }

            return(profile);
        }
Beispiel #2
0
        //TODO: Handle Exceptions;
        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 = (string)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 = (string)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"]));
                layout.AddAccessibleProfiles(profile);
            }
            layout.Sections = GetAllSectionsofLayout(layoutDetails);
            return(layout);
        }
Beispiel #3
0
        //TODO: Inspect the field modified_by in the response;
        //TODO: Returns ZCRMModule.. Inspect the method;
        private ZCRMModule GetZCRMModule(JObject moduleDetails)
        {
            ZCRMModule module = ZCRMModule.GetInstance(Convert.ToString(moduleDetails.GetValue("api_name")));

            module.Id            = Convert.ToInt64(moduleDetails.GetValue("id"));
            module.SystemName    = Convert.ToString(moduleDetails.GetValue("module_name"));
            module.SingularLabel = Convert.ToString(moduleDetails.GetValue("singular_label"));
            module.PluralLabel   = Convert.ToString(moduleDetails.GetValue("plural_label"));
            module.Creatable     = Convert.ToBoolean(moduleDetails.GetValue("creatable"));
            module.Viewable      = Convert.ToBoolean(moduleDetails.GetValue("viewable"));
            module.Editable      = Convert.ToBoolean(moduleDetails.GetValue("editable"));
            module.Convertible   = Convert.ToBoolean(moduleDetails.GetValue("convertible"));
            module.Deletable     = Convert.ToBoolean(moduleDetails.GetValue("deletable"));
            module.CustomModule  = Convert.ToBoolean(moduleDetails.GetValue("generated_type").ToString().Equals("custom"));

            JArray accessibleProfilesArray = (JArray)moduleDetails.GetValue("profiles");

            foreach (JObject accessibleProfiles in accessibleProfilesArray)
            {
                ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles.GetValue("id")), Convert.ToString(accessibleProfiles.GetValue("name")));
                module.AddAccessibleProfiles(profile);
            }
            Console.WriteLine(moduleDetails["modified_by"].Type == JTokenType.Null);
            if (moduleDetails["modified_by"].HasValues)
            {
                JObject  modifiedByObject = (JObject)moduleDetails.GetValue("modified_by");
                ZCRMUser modifiedUser     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), Convert.ToString(modifiedByObject.GetValue("name")));
                module.ModifiedBy   = modifiedUser;
                module.ModifiedTime = Convert.ToString(moduleDetails.GetValue("modified_time"));
            }
            if (moduleDetails.ContainsKey("related_lists"))
            {
                List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>();
                JArray relatedListsArray = (JArray)moduleDetails.GetValue("related_lists");
                foreach (JObject relatedListDetails in relatedListsArray)
                {
                    ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, Convert.ToString(relatedListDetails.GetValue("api_name)")));
                    SetRelatedListProperties(relatedList, relatedListDetails);
                    relatedLists.Add(relatedList);
                }
                module.RelatedLists = relatedLists;
            }
            if (moduleDetails.ContainsKey("business_card_fields"))
            {
                List <string> bcFields      = new List <string>();
                JArray        bcFieldsArray = (JArray)moduleDetails.GetValue("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);
        }
        private ZCRMModule GetZCRMModule(JObject moduleDetails)
        {
            try
            {
                ZCRMModule module = ZCRMModule.GetInstance((string)moduleDetails["api_name"]);
                if (moduleDetails.ContainsKey("global_search_supported") && moduleDetails["global_search_supported"].Type != JTokenType.Null)
                {
                    module.GlobalSearchSupported = (bool)moduleDetails["global_search_supported"];
                }
                if (moduleDetails.ContainsKey("kanban_view") && moduleDetails["kanban_view"].Type != JTokenType.Null)
                {
                    module.KanbanView = (bool)moduleDetails["kanban_view"];
                }
                module.Deletable = (bool)moduleDetails["deletable"];
                module.Creatable = (bool)moduleDetails["creatable"];
                if (moduleDetails.ContainsKey("filter_status") && moduleDetails["filter_status"].Type != JTokenType.Null)
                {
                    module.FilterStatus = (bool)moduleDetails["filter_status"];
                }
                if (moduleDetails.ContainsKey("inventory_template_supported") && moduleDetails["inventory_template_supported"].Type != JTokenType.Null)
                {
                    module.InventoryTemplateSupported = (bool)moduleDetails["inventory_template_supported"];
                }
                if (moduleDetails.ContainsKey("modified_time") && moduleDetails["modified_time"].Type != JTokenType.Null)
                {
                    module.ModifiedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(moduleDetails["modified_time"]));
                }
                module.PluralLabel = (string)moduleDetails["plural_label"];
                if (moduleDetails.ContainsKey("presence_sub_menu") && moduleDetails["presence_sub_menu"].Type != JTokenType.Null)
                {
                    module.PresenceSubMenu = (bool)moduleDetails["presence_sub_menu"];
                }
                module.Id = Convert.ToInt64(moduleDetails["id"]);
                if (moduleDetails.ContainsKey("related_list_properties") && moduleDetails["related_list_properties"].Type != JTokenType.Null)
                {
                    module.RelatedListProperties = GetRelatedListProperties((JObject)moduleDetails["related_list_properties"]);
                }
                if (moduleDetails.ContainsKey("$properties") && moduleDetails["$properties"].Type != JTokenType.Null)
                {
                    List <string> properties = new List <string>();
                    foreach (string property in (JArray)moduleDetails["$properties"])
                    {
                        properties.Add(property);
                    }
                    module.Properties = properties;
                }
                if (moduleDetails.ContainsKey("per_page") && moduleDetails["per_page"].Type != JTokenType.Null)
                {
                    module.PerPage = (int)moduleDetails["per_page"];
                }
                if (moduleDetails.ContainsKey("visibility") && moduleDetails["visibility"].Type != JTokenType.Null)
                {
                    module.Visibility = (int)moduleDetails["visibility"];
                }
                module.Convertable = (bool)moduleDetails["convertable"];
                module.Editable    = (bool)moduleDetails["editable"];
                if (moduleDetails.ContainsKey("emailTemplate_support") && moduleDetails["emailTemplate_support"].Type != JTokenType.Null)
                {
                    module.EmailTemplateSupport = (bool)moduleDetails["emailTemplate_support"];
                }
                if (moduleDetails["profiles"].HasValues)
                {
                    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.ContainsKey("filter_supported") && moduleDetails["filter_supported"].Type != JTokenType.Null)
                {
                    module.FilterSupported = (bool)moduleDetails["filter_supported"];
                }
                if (moduleDetails.ContainsKey("display_field") && moduleDetails["display_field"].Type != JTokenType.Null)
                {
                    module.DisplayField = (string)moduleDetails["display_field"];
                }
                if (moduleDetails.ContainsKey("search_layout_fields") && moduleDetails["search_layout_fields"].Type != JTokenType.Null)
                {
                    List <string> layout_Fields = new List <string>();
                    foreach (string layout_Field in (JArray)moduleDetails["search_layout_fields"])
                    {
                        layout_Fields.Add(layout_Field);
                    }
                    module.SearchLayoutFields = layout_Fields;
                }
                if (moduleDetails.ContainsKey("kanban_view_supported") && moduleDetails["kanban_view_supported"].Type != JTokenType.Null)
                {
                    module.KanbanViewSupported = (bool)moduleDetails["kanban_view_supported"];
                }
                module.WebLink        = (string)moduleDetails["web_link"];
                module.SequenceNumber = (int)moduleDetails["sequence_number"];
                module.SingularLabel  = (string)moduleDetails["singular_label"];
                module.Viewable       = (bool)moduleDetails["viewable"];
                module.ApiSupported   = (bool)(moduleDetails["api_supported"]);
                if (moduleDetails.ContainsKey("quick_create") && moduleDetails["quick_create"].Type != JTokenType.Null)
                {
                    module.QuickCreate = (bool)(moduleDetails["quick_create"]);
                }
                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.CustomModule = (bool)(moduleDetails["generated_type"].ToString().Equals("custom"));
                if (moduleDetails.ContainsKey("feeds_required") && moduleDetails["feeds_required"].Type != JTokenType.Null)
                {
                    module.FeedsRequired = (bool)(moduleDetails["feeds_required"]);
                }
                if (moduleDetails.ContainsKey("scoring_supported") && moduleDetails["scoring_supported"].Type != JTokenType.Null)
                {
                    module.ScoringSupported = (bool)(moduleDetails["scoring_supported"]);
                }
                if (moduleDetails.ContainsKey("webform_supported") && moduleDetails["webform_supported"].Type != JTokenType.Null)
                {
                    module.WebformSupported = (bool)(moduleDetails["webform_supported"]);
                }
                if (moduleDetails.ContainsKey("arguments") && moduleDetails["arguments"].Type != JTokenType.Null)
                {
                    if (moduleDetails["arguments"].HasValues)
                    {
                        List <ZCRMWebTabArguments> argumentsList = new List <ZCRMWebTabArguments>();
                        JArray argumentsJArr = (JArray)moduleDetails["arguments"];
                        foreach (JObject argumentsJObj in argumentsJArr)
                        {
                            ZCRMWebTabArguments argumentsIns = ZCRMWebTabArguments.GetInstance();
                            if (argumentsJObj.ContainsKey("name") && argumentsJObj["name"].Type != JTokenType.Null)
                            {
                                argumentsIns.Name = (string)argumentsJObj["name"];
                            }
                            if (argumentsJObj.ContainsKey("value") && argumentsJObj["value"].Type != JTokenType.Null)
                            {
                                argumentsIns.Value = (string)argumentsJObj["value"];
                            }
                            argumentsList.Add(argumentsIns);
                        }
                        module.WebTabArguments = argumentsList;
                    }
                }
                module.SystemName = (string)moduleDetails["module_name"];
                if (moduleDetails.ContainsKey("business_card_field_limit") && moduleDetails["business_card_field_limit"].Type != JTokenType.Null)
                {
                    module.BusinessCardFieldLimit = (int)moduleDetails["business_card_field_limit"];
                }
                if (moduleDetails.ContainsKey("custom_view") && moduleDetails["custom_view"].Type != JTokenType.Null)
                {
                    module.CustomView = GetZCRMCustomView((string)moduleDetails["api_name"], (JObject)moduleDetails["custom_view"]);
                }
                if (moduleDetails.ContainsKey("parent_module") && moduleDetails["parent_module"].Type != JTokenType.Null)
                {
                    if (moduleDetails["parent_module"].HasValues)
                    {
                        JObject    parent_module   = (JObject)moduleDetails["parent_module"];
                        ZCRMModule parentModuleIns = ZCRMModule.GetInstance((string)parent_module["api_name"]);
                        parentModuleIns.Id  = Convert.ToInt64(parent_module["id"]);
                        module.ParentModule = parentModuleIns;
                    }
                }
                if (moduleDetails.ContainsKey("territory") && moduleDetails["territory"].Type != JTokenType.Null)
                {
                    JObject       territoryJobj = (JObject)moduleDetails["territory"];
                    ZCRMTerritory territoryIns  = ZCRMTerritory.GetInstance(Convert.ToInt64(territoryJobj["id"]));
                    territoryIns.Name         = (string)territoryJobj["name"];
                    territoryIns.Subordinates = (bool)territoryJobj["subordinates"];
                    module.Territory          = territoryIns;
                }
                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("fields") && moduleDetails["fields"].Type != JTokenType.Null)
                {
                    JArray fieldArray = (JArray)moduleDetails["fields"];
                    module.Fields = ModuleAPIHandler.GetInstance(ZCRMModule.GetInstance((string)moduleDetails["api_name"])).GetFields(fieldArray);
                }
                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 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"]));
            }
            if (profileDetails.ContainsKey("permissions_details") && profileDetails["permissions_details"].Type != JTokenType.Null)
            {
                JArray permissionsJArr = (JArray)profileDetails["permissions_details"];
                foreach (JObject permissionsJObj in permissionsJArr)
                {
                    ZCRMProfilePermissions profilePermissions = ZCRMProfilePermissions.GetInstance();
                    if (permissionsJObj.ContainsKey("display_label") && permissionsJObj["display_label"].Type != JTokenType.Null)
                    {
                        profilePermissions.DisplayLabel = (string)permissionsJObj["display_label"];
                    }
                    if (permissionsJObj.ContainsKey("module") && permissionsJObj["module"].Type != JTokenType.Null)
                    {
                        profilePermissions.Module = (string)permissionsJObj["module"];
                    }
                    if (permissionsJObj.ContainsKey("name") && permissionsJObj["name"].Type != JTokenType.Null)
                    {
                        profilePermissions.Name = (string)permissionsJObj["name"];
                    }
                    if (permissionsJObj.ContainsKey("id") && permissionsJObj["id"].Type != JTokenType.Null)
                    {
                        profilePermissions.Id = (long)permissionsJObj["id"];
                    }
                    if (permissionsJObj.ContainsKey("enabled") && permissionsJObj["enabled"].Type != JTokenType.Null)
                    {
                        profilePermissions.Enabled = (bool)permissionsJObj["enabled"];
                    }
                    profile.SetPermissionsDetails(profilePermissions);
                }
            }
            if (profileDetails.ContainsKey("sections") && profileDetails["sections"].Type != JTokenType.Null)
            {
                JArray sectionsJArr = (JArray)profileDetails["sections"];
                foreach (JObject sectionsJObj in sectionsJArr)
                {
                    ZCRMProfileSection sectionIns = ZCRMProfileSection.GetInstance((string)sectionsJObj["name"]);
                    if (sectionsJObj.ContainsKey("categories") && sectionsJObj["categories"].Type != JTokenType.Null)
                    {
                        JArray categoriesJArr = (JArray)sectionsJObj["categories"];
                        foreach (JObject categoriesJObj in categoriesJArr)
                        {
                            ZCRMProfileCategory categoryIns = ZCRMProfileCategory.GetInstance((string)categoriesJObj["name"]);
                            if (categoriesJObj.ContainsKey("display_label") && categoriesJObj["display_label"].Type != JTokenType.Null)
                            {
                                categoryIns.DisplayLabel = (string)categoriesJObj["display_label"];
                            }
                            if (categoriesJObj.ContainsKey("module") && categoriesJObj["module"].Type != JTokenType.Null)
                            {
                                categoryIns.Module = (string)categoriesJObj["module"];
                            }
                            if (categoriesJObj.ContainsKey("permissions_details") && categoriesJObj["permissions_details"].Type != JTokenType.Null && categoriesJObj["permissions_details"].HasValues)
                            {
                                List <long> permissionsIds = new List <long>();
                                foreach (long id in categoriesJObj["permissions_details"])
                                {
                                    permissionsIds.Add(id);
                                }
                                categoryIns.PermissionIds = permissionsIds;
                            }
                            sectionIns.SetCategories(categoryIns);
                        }
                    }
                    profile.SetProfileSection(sectionIns);
                }
            }
            return(profile);
        }
        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);
        }
        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"];
            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 = (string)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 = (string)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;
            }

            return(user);
        }
 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);
     }
 }
Beispiel #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);
        }