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);
        }
Пример #2
0
 private void SetTrashRecordProperties(JObject trashRecordDetails)
 {
     foreach (KeyValuePair <string, JToken> trashRecordDetail in trashRecordDetails)
     {
         string fieldAPIName = Convert.ToString(trashRecordDetail.Value);
         if (fieldAPIName.Equals("Created_By"))
         {
             JObject  createdByObject = (JObject)trashRecordDetail.Value;
             ZCRMUser createdUser     = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject.GetValue("id")), Convert.ToString(createdByObject.GetValue("name")));
             trashRecord.CreatedBy = createdUser;
         }
         else if (fieldAPIName.Equals("deleted_by"))
         {
             JObject  modifiedByObject = (JObject)trashRecordDetail.Value;
             ZCRMUser DeletedByUser    = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject.GetValue("id")), Convert.ToString(modifiedByObject.GetValue("name")));
             trashRecord.CreatedBy = DeletedByUser;
         }
         else if (fieldAPIName.Equals("display_name"))
         {
             trashRecord.DisplayName = Convert.ToString(trashRecordDetail.Value);
         }
         else if (fieldAPIName.Equals("deleted_time"))
         {
             trashRecord.DeletedTime = Convert.ToString(trashRecordDetail.Value);
         }
     }
 }
Пример #3
0
 private void SetBulkWriteRecordProperties(JObject recordJSON)
 {
     foreach (KeyValuePair <string, JToken> bulkRecord in recordJSON)
     {
         if (bulkRecord.Key.Equals("id") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.writeRecord.JobId = (long)bulkRecord.Value;
         }
         else if (bulkRecord.Key.Equals("created_by") && bulkRecord.Value.Type != JTokenType.Null)
         {
             JObject  createdByObj = (JObject)bulkRecord.Value;
             ZCRMUser createdBy    = ZCRMUser.GetInstance((long)createdByObj["id"], (string)createdByObj["name"]);
             this.writeRecord.CreatedBy = createdBy;
         }
         else if (bulkRecord.Key.Equals("created_time") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.writeRecord.CreatedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(bulkRecord.Value));
         }
         else if (bulkRecord.Key.Equals("status") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.writeRecord.Status = (string)bulkRecord.Value;
         }
         else if (bulkRecord.Key.Equals("character_encoding") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.writeRecord.CharacterEncoding = (string)bulkRecord.Value;
         }
         else if (bulkRecord.Key.Equals("resource") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.SetZCRMBulkWriteResourceListofObject((JArray)bulkRecord.Value);
         }
         else if (bulkRecord.Key.Equals("result") && bulkRecord.Value.Type != JTokenType.Null)
         {
             JObject        createdObject = (JObject)bulkRecord.Value;
             ZCRMBulkResult result        = ZCRMBulkResult.GetInstance();
             if (createdObject.ContainsKey("download_url"))
             {
                 result.DownloadUrl = (string)createdObject["download_url"];
             }
             this.writeRecord.Result = result;
         }
         else if (bulkRecord.Key.Equals("operation") && bulkRecord.Value.Type != JTokenType.Null)
         {
             this.writeRecord.Operation = (string)bulkRecord.Value;
         }
         else if (bulkRecord.Key.Equals("callback") && bulkRecord.Value.Type != JTokenType.Null)
         {
             ZCRMBulkCallBack callback = ZCRMBulkCallBack.GetInstance();
             JObject          jsonObj  = (JObject)bulkRecord.Value;
             if (jsonObj.ContainsKey("url"))
             {
                 callback.Url = (string)jsonObj["url"];
             }
             if (jsonObj.ContainsKey("method"))
             {
                 callback.Method = (string)jsonObj["method"];
             }
             this.writeRecord.Callback = callback;
         }
     }
 }
Пример #4
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));
                }
            }
        }
Пример #5
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);
        }
Пример #6
0
        public Dictionary <string, long> ConvertRecord(ZCRMRecord potential, ZCRMUser assignToUser)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.POST;

                urlPath = record.ModuleAPIName + "/" + record.EntityId + "/actions/convert";

                JObject requestBodyObject = new JObject();

                JArray dataArray = new JArray();

                JObject dataObject = new JObject();

                if (assignToUser != null)
                {
                    dataObject.Add("assign_to", assignToUser.Id.ToString());
                }

                if (potential != null)
                {
                    dataObject.Add(APIConstants.DEALS, GetInstance(potential).GetZCRMRecordAsJSON());
                }

                dataArray.Add(dataObject);

                requestBodyObject.Add(APIConstants.DATA, dataArray);

                requestBody = requestBodyObject;

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray responseJson = (JArray)response.ResponseJSON[APIConstants.DATA];

                JObject convertedIdsJSON = (JObject)responseJson[0];

                Dictionary <string, long> convertedIds = new Dictionary <string, long>();

                convertedIds.Add(APIConstants.CONTACTS, Convert.ToInt64(convertedIdsJSON[APIConstants.CONTACTS]));

                if (convertedIdsJSON[APIConstants.ACCOUNTS].Type != JTokenType.Null)
                {
                    convertedIds.Add(APIConstants.ACCOUNTS, Convert.ToInt64(convertedIdsJSON[APIConstants.ACCOUNTS]));
                }

                if (convertedIdsJSON[APIConstants.DEALS].Type != JTokenType.Null)
                {
                    convertedIds.Add(APIConstants.DEALS, Convert.ToInt64(convertedIdsJSON[APIConstants.DEALS]));
                }

                return(convertedIds);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);

                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Пример #7
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 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);
        }
        private ZCRMNote GetZCRMNote(JObject noteDetails, ZCRMNote note)
        {
            if (note == null)
            {
                note = ZCRMNote.GetInstance(parentRecord, Convert.ToInt64(noteDetails.GetValue("id")));
            }
            note.Id = Convert.ToInt64(noteDetails.GetValue("id"));
            if (noteDetails.GetValue("Note_Title") != null)
            {
                note.Title = Convert.ToString(noteDetails.GetValue("Note_Title"));
            }
            if (noteDetails.GetValue("Note_Content") != null)
            {
                note.Content = Convert.ToString(noteDetails.GetValue("Note_Content"));
            }
            JObject  createdByObject = (JObject)noteDetails.GetValue("Created_By");
            ZCRMUser createdBy       = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject.GetValue("id")), Convert.ToString(createdByObject.GetValue("name")));

            note.CreatedBy   = createdBy;
            note.CreatedTime = Convert.ToString(noteDetails.GetValue("Created_Time"));

            JObject  modifiedByObject = (JObject)noteDetails.GetValue("Modified_By");
            ZCRMUser modifiedBy       = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject.GetValue("id")), Convert.ToString(modifiedByObject.GetValue("name")));

            note.ModifiedBy   = modifiedBy;
            note.ModifiedTime = Convert.ToString(noteDetails.GetValue("Modified_Time"));

            if (noteDetails.GetValue("Owner") != null)
            {
                JObject  ownerObject = (JObject)noteDetails.GetValue("Owner");
                ZCRMUser owner       = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject.GetValue("id")), Convert.ToString(ownerObject.GetValue("name")));
                note.NotesOwner = owner;
            }
            else
            {
                note.NotesOwner = createdBy;
            }
            if (noteDetails.GetValue("$attachments") != null)
            {
                JArray attachmentsArray = (JArray)noteDetails.GetValue("$attachments");
                foreach (JObject attachmentDetails in attachmentsArray)
                {
                    note.AddAttachment(GetZCRMAttachment(attachmentDetails));
                }
            }
            return(note);
        }
        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);
        }
Пример #11
0
        public ZCRMRecord CreateLead(LeadRequest leadRequest)
        {
            ZCRMRecord record = ZCRMRecord.GetInstance(ZohoConstants.LEAD_MODULE_STRING, null);

            record.SetFieldValue("Last_Name", leadRequest.Name); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
            record.SetFieldValue("Email", leadRequest.Email);
            record.SetFieldValue("Description", leadRequest.Description);
            record.SetFieldValue("Email_Opt_Out", true);
            record.SetFieldValue("No_of_Employees", leadRequest.NumberOfEmployees);
            ZCRMUser owner = ZCRMUser.GetInstance(680990340);//User Id

            record.Owner = owner;
            APIResponse responseIns = record.Create();//To call the create record method
            ZCRMRecord  record1     = (ZCRMRecord)responseIns.Data;

            return(record1);
        }
Пример #12
0
 private void SetBulkReadRecordProperties(JObject recordJSON)
 {
     foreach (KeyValuePair <string, JToken> token in recordJSON)
     {
         string fieldAPIName = token.Key;
         if (fieldAPIName.Equals("id") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.JobId = Convert.ToInt64(token.Value);
         }
         else if (fieldAPIName.Equals("operation") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.Operation = token.Value.ToString();
         }
         else if (fieldAPIName.Equals("state") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.State = token.Value.ToString();
         }
         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"]);
             this.readRecord.CreatedBy = createdUser;
         }
         else if (fieldAPIName.Equals("created_time") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.CreatedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(token.Value));
         }
         else if (fieldAPIName.Equals("result") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.Result = this.SetZCRMResultObject((JObject)token.Value);
         }
         else if (fieldAPIName.Equals("query") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.Query = this.SetZCRMBulkQueryObject((JObject)token.Value);
         }
         else if (fieldAPIName.Equals("callback") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.CallBack = this.SetZCRMBulkCallBackObject((JObject)token.Value);
         }
         else if (fieldAPIName.Equals("file_type") && token.Value.Type != JTokenType.Null)
         {
             this.readRecord.FileType = token.Value.ToString();
         }
     }
 }
Пример #13
0
        //TODO: Handle exceptions appropriately;
        public Dictionary <string, long> ConvertRecord(ZCRMRecord potential, ZCRMUser assignToUser)
        {
            try{
                requestMethod = APIConstants.RequestMethod.POST;
                urlPath       = record.ModuleAPIName + "/" + record.EntityId;
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                JObject dataObject        = new JObject();
                if (assignToUser != null)
                {
                    dataObject.Add("assign_to", assignToUser.Id.ToString());
                }
                if (potential != null)
                {
                    dataObject.Add("Deals", GetInstance(potential).GetZCRMRecordAsJSON());
                }
                dataArray.Add(dataObject);
                requestBodyObject.Add("data", dataArray);
                requestBody = requestBodyObject;

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();


                JArray  responseJson     = (JArray)response.ResponseJSON.GetValue("data");
                JObject convertedIdsJSON = (JObject)responseJson[0];

                Dictionary <string, long> convertedIds = new Dictionary <string, long>();
                convertedIds.Add("Contacts", Convert.ToInt64(convertedIdsJSON.GetValue("Contacts")));
                if (convertedIdsJSON.GetValue("Accounts") != null)
                {
                    convertedIds.Add("Accounts", Convert.ToInt64(convertedIdsJSON.GetValue("Accounts")));
                }
                if (convertedIdsJSON.GetValue("Deals") != null)
                {
                    convertedIds.Add("Deals", Convert.ToInt64(convertedIdsJSON.GetValue("Deals")));
                }

                return(convertedIds);
            }catch (Exception e) {
                //TODO: Log the info;
                Console.WriteLine("Exception caught at ConvertRecord");
                throw new ZCRMException(e.ToString());
            }
        }
        //TODO: Handle Exceptions;
        private ZCRMAttachment GetZCRMAttachment(JObject attachmentDetails)
        {
            ZCRMAttachment attachment = ZCRMAttachment.GetInstance(parentRecord, Convert.ToInt64(attachmentDetails.GetValue("id")));
            string         fileName   = Convert.ToString(attachmentDetails.GetValue("File_Name"));

            if (fileName != null)
            {
                attachment.FileName = fileName;
                attachment.FileType = fileName.Substring(fileName.LastIndexOf('.') + 1);
            }
            if (attachmentDetails.ContainsKey("Size"))
            {
                attachment.Size = Convert.ToInt64(attachmentDetails.GetValue("Size"));
            }
            if (attachmentDetails.ContainsKey("Created_By"))
            {
                JObject  createdByObject = (JObject)attachmentDetails.GetValue("Created_By");
                ZCRMUser createdBy       = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject.GetValue("id")), Convert.ToString(createdByObject.GetValue("name")));
                attachment.CreatedBy   = createdBy;
                attachment.CreatedTime = Convert.ToString(attachmentDetails.GetValue("Created_Time"));

                if (attachmentDetails.GetValue("Owner") != null)
                {
                    JObject  ownerObject = (JObject)attachmentDetails.GetValue("Owner");
                    ZCRMUser owner       = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject.GetValue("id")), Convert.ToString(ownerObject.GetValue("name")));
                    attachment.Owner = owner;
                }
                else
                {
                    attachment.Owner = createdBy;
                }
            }
            if (attachmentDetails.ContainsKey("Modified_By"))
            {
                JObject  modifiedByObject = (JObject)attachmentDetails.GetValue("Modified_By");
                ZCRMUser modifiedBy       = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject.GetValue("id")), Convert.ToString(modifiedByObject.GetValue("name")));
                attachment.ModifiedBy   = modifiedBy;
                attachment.ModifiedTime = Convert.ToString(attachmentDetails.GetValue("Modified_Time"));
            }

            return(attachment);
        }
Пример #15
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 = (string)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 = (string)attachmentDetails["Modified_Time"];
            }

            return(attachment);
        }
Пример #16
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);
         }
     }
 }
        //TODO: Handle exceptions;
        private ZCRMRole GetZCRMRole(JObject roleDetails)
        {
            ZCRMRole role = ZCRMRole.GetInstance((long)roleDetails["id"], (string)roleDetails["name"]);

            role.Label = (string)roleDetails["display_label"];
            if (roleDetails.ContainsKey("forecast_manager") && roleDetails["forecast_manager"].Type != JTokenType.Null)
            {
                JObject  forecast_manager = (JObject)roleDetails["forecast_manager"];
                ZCRMUser user             = ZCRMUser.GetInstance();
                if (forecast_manager.ContainsKey("id") && forecast_manager["id"].Type != JTokenType.Null)
                {
                    user.Id = (long)forecast_manager["id"];
                }
                if (forecast_manager.ContainsKey("name") && forecast_manager["name"].Type != JTokenType.Null)
                {
                    user.FullName = (string)forecast_manager["name"];
                }
                role.ForecastManager = user;
            }
            if (roleDetails.ContainsKey("share_with_peers") && roleDetails["share_with_peers"].Type != JTokenType.Null)
            {
                role.ShareWithPeers = (bool)roleDetails["share_with_peers"];
            }
            if (roleDetails.ContainsKey("description") && roleDetails["description"].Type != JTokenType.Null)
            {
                role.Description = (string)roleDetails["description"];
            }
            ZCRMRole reportingTo = null;

            if (roleDetails.ContainsKey("reporting_to") && roleDetails["reporting_to"].Type != JTokenType.Null)
            {
                JObject reportingToObject = (JObject)roleDetails["reporting_to"];
                reportingTo = ZCRMRole.GetInstance((long)reportingToObject["id"], (string)reportingToObject["name"]);
            }
            role.ReportingTo = reportingTo;
            role.AdminUser   = (bool)roleDetails["admin_user"];
            return(role);
        }
 public APIResponse UpdateUser(ZCRMUser userInstance)
 {
     try
     {
         requestMethod = APIConstants.RequestMethod.PUT;
         if (userInstance.Id == 0)
         {
             throw new ZCRMException("User ID MUST not be null for UpdateUser operation.");
         }
         urlPath = "users/" + userInstance.Id;
         JObject requestBodyObject = new JObject();
         JArray  dataArray         = new JArray();
         dataArray.Add(ConstructJSONForUser(userInstance));
         requestBodyObject.Add(APIConstants.USERS, dataArray);
         requestBody = requestBodyObject;
         APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();
         return(response);
     }
     catch (Exception e) when(!(e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
        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);
        }
Пример #20
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);
                    }
                }
            }
        }
 /// <summary>
 /// Updates the user.
 /// </summary>
 /// <returns>The user instance.</returns>
 /// <param name="userInstance">User instance.</param>
 public APIResponse UpdateUser(ZCRMUser userInstance)
 {
     return(OrganizationAPIHandler.GetInstance().UpdateUser(userInstance));
 }
        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);
            }
        }
Пример #23
0
 //TODO<IMPORTANT>: Lots of performance tune-ups are needed and needs plenty of testing!!;
 public void SetRecordProperties(JObject recordJSON, ZCRMRecord record)
 {
     //JObject recordDetails = new JObject(recordJSON);
     //TODO: If Performance is needed implement JSONTextReader or JSONReader and put thought into it later after completing the SDK;
     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((JArray)token.Value);
         }
         else if (fieldAPIName.Equals("Participants"))
         {
             SetParticipants((JArray)token.Value);
         }
         else if (fieldAPIName.Equals("Pricing_Details"))
         {
             SetPriceDetails((JArray)token.Value);
         }
         else if (fieldAPIName.Equals("Created_By"))
         {
             JObject  createdObject = (JObject)token.Value;
             ZCRMUser createdUser   = ZCRMUser.GetInstance(Convert.ToInt64(createdObject.GetValue("id")), Convert.ToString(createdObject.GetValue("name")));
             record.CreatedBy = createdUser;
         }
         else if (fieldAPIName.Equals("Modified_By"))
         {
             JObject  modifiedObject = (JObject)token.Value;
             ZCRMUser modifiedBy     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedObject.GetValue("id")), Convert.ToString(modifiedObject.GetValue("name")));
         }
         else if (fieldAPIName.Equals("Created_Time"))
         {
             record.CreatedTime = Convert.ToString(token.Value);
         }
         else if (fieldAPIName.Equals("Modified_Time"))
         {
             record.ModifiedTime = Convert.ToString(token.Value);
         }
         else if (fieldAPIName.Equals("Owner"))
         {
             JObject  ownerObject = (JObject)token.Value;
             ZCRMUser ownerUser   = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject.GetValue("id")), Convert.ToString(ownerObject.GetValue("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.GetValue("id")));
             layout.Name = Convert.ToString(layoutObject.GetValue("name"));
         }
         else if (fieldAPIName.Equals("Handler") && token.Value.Type != JTokenType.Null)
         {
             JObject  handlerObject = (JObject)token.Value;
             ZCRMUser handler       = ZCRMUser.GetInstance(Convert.ToInt64(handlerObject.GetValue("id")), Convert.ToString(handlerObject.GetValue("name")));
             record.SetFieldValue(fieldAPIName, handler);
         }
         else if (fieldAPIName.Equals("Remind_At") && token.Value.Type == JTokenType.Null)
         {
             JObject remindObject = (JObject)token.Value;
             record.SetFieldValue(fieldAPIName, remindObject.GetValue("ALARM"));
         }
         else if (fieldAPIName.Equals("Recurring_Activity") && token.Value.Type != JTokenType.Null)
         {
             JObject recurringActivityObject = (JObject)token.Value;
             record.SetFieldValue(fieldAPIName, recurringActivityObject.GetValue("RRULE"));
         }
         else if (fieldAPIName.Equals("$line_tax"))
         {
             JArray taxDetails = (JArray)token.Value;
             foreach (JObject taxDetail in taxDetails)
             {
                 ZCRMTax tax = ZCRMTax.GetInstance(Convert.ToString(taxDetail.GetValue("name")));
                 tax.Percentage = Convert.ToDouble(taxDetail.GetValue("percentage"));
                 tax.Value      = Convert.ToDouble(taxDetail.GetValue("value"));
                 record.AddTax(tax);
             }
         }
         else if (fieldAPIName.Equals("Tax") && token.Value.Type != JTokenType.Null)
         {
             JArray taxNames = (JArray)token.Value;
             int    arrayLen = taxNames.Count;
             for (int i = 0; i < arrayLen; i++)
             {
                 ZCRMTax tax = ZCRMTax.GetInstance(Convert.ToString(taxNames[i]));
                 record.AddTax(tax);
             }
         }
         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.GetValue("id")));
             lookupRecord.LookupLabel = Convert.ToString(lookupDetails.GetValue("name"));
             record.SetFieldValue(fieldAPIName, lookupRecord);
         }
         else if (token.Value is JArray)
         {
             JArray        jsonArray = (JArray)token.Value;
             List <object> values    = new List <object>();
             foreach (JObject jsonObject in jsonArray)
             {
                 values.Add(jsonObject);
             }
             record.SetFieldValue(fieldAPIName, values);
         }
         else
         {
             record.SetFieldValue(fieldAPIName, token.Value);
         }
     }
 }
 public ZCRMRecord SetRecordProperties(string ModuleAPIName, Dictionary <string, object> fieldvsValue, int rowNumber)
 {
     recordIns           = null;
     recordIns           = new ZCRMRecord(ModuleAPIName);
     recordIns.RowNumber = rowNumber;
     foreach (KeyValuePair <string, object> data in fieldvsValue)
     {
         if (data.Key.Equals("Id") || data.Key.Equals("RECORD_ID"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.EntityId = Convert.ToInt64(data.Value);
             }
         }
         else if (data.Key.Equals("Created_By"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 ZCRMUser createdBy = recordIns.CreatedBy ?? ZCRMUser.GetInstance();
                 createdBy.Id        = Convert.ToInt64(data.Value);
                 recordIns.CreatedBy = createdBy;
             }
         }
         else if (data.Key.Equals("Modified_By"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 ZCRMUser modifiedBy = recordIns.ModifiedBy ?? ZCRMUser.GetInstance();
                 modifiedBy.Id        = Convert.ToInt64(data.Value);
                 recordIns.ModifiedBy = modifiedBy;
             }
         }
         else if (data.Key.Equals("Created_Time"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.CreatedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(data.Value));
             }
         }
         else if (data.Key.Equals("Modified_Time"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.ModifiedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(data.Value));
             }
         }
         else if (data.Key.Equals("Owner"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 ZCRMUser owner = recordIns.Owner != null ? recordIns.Owner : ZCRMUser.GetInstance();
                 owner.Id        = Convert.ToInt64(data.Value);
                 recordIns.Owner = owner;
             }
         }
         else if (data.Key.Equals("STATUS"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.Status = (string)data.Value;
             }
         }
         else if (data.Key.Equals("ERRORS"))
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.Error = (string)data.Value;
             }
         }
         else if (data.Key.StartsWith("$", StringComparison.Ordinal))
         {
             var    regex     = new Regex(Regex.Escape("$"));
             string fieldName = regex.Replace(data.Key, "", 1);
             //string fieldName = fieldAPINames[i].re("\\$", "");
             if (APIConstants.PROPERTIES_AS_FILEDS.Contains(fieldName))
             {
                 if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
                 {
                     recordIns.SetFieldValue(fieldName, data.Value);
                 }
             }
             else
             {
                 if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
                 {
                     recordIns.SetProperty(fieldName, data.Value);
                 }
             }
         }
         else
         {
             if (data.Value != null && !String.IsNullOrEmpty(Convert.ToString(data.Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(data.Value)))
             {
                 recordIns.SetFieldValue(data.Key, data.Value);
             }
         }
     }
     return(recordIns);
 }
        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);
        }
Пример #26
0
 /// <summary>
 /// To convert the record based on potential record  and ZCRMUser class instance.
 /// </summary>
 /// <returns>Dictionary(String,Long).</returns>
 /// <param name="potential">ZCRMRecord class instance</param>
 /// <param name="assignToUser">ZCRMUser class instance</param>
 public Dictionary <string, long> Convert(ZCRMRecord potential, ZCRMUser assignToUser)
 {
     return(EntityAPIHandler.GetInstance(this).ConvertRecord(potential, assignToUser));
 }
        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 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);
        }
Пример #29
0
        //public BulkAPIResponse<ZCRMRecord> InsertInvestor(InvestorModel investor)
        //{

        //    ZCRMRestClient.Initialize(config);
        //    ZohoOAuthClient client = ZohoOAuthClient.GetInstance();
        //    string refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
        //    string userMailId = "*****@*****.**";
        //    ZohoOAuthTokens tokens = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
        //    List<ZCRMRecord> records = new List<ZCRMRecord>();
        //    ZCRMRecord record1 = new ZCRMRecord("accounts"); //module api name

        //    record1.SetFieldValue("Account_Name", investor.UserName);
        //    record1.SetFieldValue("Email", investor.UserName);
        //    record1.SetFieldValue("Username", investor.UserName);
        //    record1.SetFieldValue("Industry", "1");
        //    record1.SetFieldValue("Status", "1");
        //    record1.SetFieldValue("Phone", investor.MobileNumber);
        //    record1.SetFieldValue("Fax", investor.MobileNumber);
        //    record1.SetFieldValue("Employees", 1);
        //    record1.SetFieldValue("Age", investor.Age);
        //    record1.SetFieldValue("Gender", investor.Gender);
        //    record1.SetFieldValue("NRIC_Number", investor.NRIC_Number);
        //    record1.SetFieldValue("Passport_Number", investor.PassportNumber);
        //    record1.SetFieldValue("Date_Of_Birth", investor.DateOfBirth.Value);
        //    record1.SetFieldValue("Sign_Up_Date", investor.DateCreated.Value.Date.ToString());
        //    record1.SetFieldValue("Total_Invested", investor.TotalInvestedAmount);
        //    record1.SetFieldValue("Admin_Verification", investor.AdminVerification);
        //    record1.SetFieldValue("Number_Of_Delinquent_Off_Note", investor.numofdelinquent);
        //    record1.SetFieldValue("Number_Of_Fully_Paid_Note", investor.NumberOfFullyPaidNotes);
        //    record1.SetFieldValue("Number_of_Close_Off_Note", investor.NumOfCloseOff);
        //    record1.SetFieldValue("Qualified_Date", investor.QualifiedDate.Value.Date.ToString());
        //    if (investor.LastLogin == null)
        //    {
        //        investor.LastLogin = investor.DateCreated;
        //    }
        //    record1.SetFieldValue("Last_Login", investor.LastLogin.Value.Date.ToString());
        //    record1.SetFieldValue("Number_Of_Deliquent_Note", investor.numofdelinquent);
        //    record1.SetFieldValue("Sum_of_Number_Invested_Note", investor.NumberOfInvested);
        //    record1.SetFieldValue("Current_in_Funding_Amount", investor.CurrentInFunding);
        //    record1.SetFieldValue("Sum_of_Ledge_Amount", investor.ActualAmount);
        //    record1.SetFieldValue("Total_Amount_Received", investor.TotalAmountReceived);
        //    record1.SetFieldValue("Total_Delinquent_Amount", investor.outstandingPI);
        //    record1.SetFieldValue("Outstanding_L", investor.outstanding_I);
        //    record1.SetFieldValue("Outstanding_P", investor.outstanding_P);
        //    record1.SetFieldValue("Principal_Received", investor.PaidP);
        //    record1.SetFieldValue("Interest_Received", investor.PaidI);
        //    record1.CreatedTime = DateTime.UtcNow.Ticks.ToString();
        //    records.Add(record1);


        //    ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts"); //module api name
        //    BulkAPIResponse<ZCRMRecord> response = moduleIns.CreateRecords(records); //records - list of ZCRMRecord instances filled with required data for upsert.
        //    List<ZCRMRecord> insertedRecords = response.BulkData; //upsertedRecords - list of ZCRMRecord instance
        //    foreach (var entityID in response.BulkData)
        //    {
        //        var newID = new tbl_CheckID
        //        {
        //            IDZoho = entityID.EntityId,
        //            EmailMS = investor.UserName
        //        };
        //        dbzoho.tbl_CheckID.Add(newID);
        //        dbzoho.SaveChanges();
        //    }

        //    List<EntityResponse> entityResponses = response.BulkEntitiesResponse; //entityResponses - list of EntityResponses instance
        //    return response;
        //}
        public void UpdateIssuer(IssuerModel issuer)
        {
            var id = dbzoho.tbl_CheckID.FirstOrDefault(p => p.EmailMS == issuer.UserName);

            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            ZCRMRecord        record1      = new ZCRMRecord("accounts"); //module api name

            record1.EntityId = id.IDZoho;
            record1.SetFieldValue("id", id.IDZoho);
            record1.SetFieldValue("Account_Name", issuer.UserName);
            record1.SetFieldValue("Full_Name", issuer.FullName);
            record1.SetFieldValue("Username", issuer.UserName);
            record1.SetFieldValue("Industry", "1");
            record1.SetFieldValue("Company_Name", issuer.BusinessName.ToString());
            record1.SetFieldValue("Phone", issuer.MobileNumber);
            record1.SetFieldValue("Fax", issuer.MobileNumber);
            record1.SetFieldValue("Employees", 1);
            record1.SetFieldValue("Total_Amount_Disbursed", issuer.totaldisbursed);
            record1.SetFieldValue("Last_Repayment_Date", issuer.LastRepaymentDate.Value.ToString());
            record1.SetFieldValue("Days_Overdue", issuer.daysoverdue);
            record1.SetFieldValue("Issuer_Account_Balance", issuer.ActualAmount);
            record1.SetFieldValue("Outstanding_Amount_with_Late_Fee", issuer.outamountwithlf);
            record1.SetFieldValue("Outstanding_Amount_no_Late_Fee", issuer.outamountwithoutlf);
            record1.SetFieldValue("Outstanding_Late_Fee", issuer.outstandinglf);
            record1.SetFieldValue("Total_Amount_Overdue", issuer.overdueamount);
            record1.SetFieldValue("Total_Principle_Paid", issuer.totalpaidprincipal);
            record1.SetFieldValue("Total_Interest_Paid", issuer.totalpaidinterest);
            record1.SetFieldValue("Total_Late_Fee_Paid", issuer.paidlatefees);
            record1.SetFieldValue("Total_Late_Interest_Paid", issuer.totalpaidlateinterest);
            record1.SetFieldValue("Total_Paid_Amount", issuer.TotalPaidAmount);
            records.Add(record1);


            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                   //module api name
            BulkAPIResponse <ZCRMRecord> responseIns = moduleIns.UpdateRecords(records); //To call the Update record method

            Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode);         //To get Update record http response code
            foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
            {
                Console.WriteLine("Status:" + response.Status);        //To get Update record response status
                Console.WriteLine("Message:" + response.Message);      //To get Update record response message
                Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
                ZCRMRecord record11 = (ZCRMRecord)response.Data;
                Console.WriteLine(record11.EntityId);                  //To get inserted record id
                Console.WriteLine(record11.CreatedTime);
                Console.WriteLine(record11.ModifiedTime);
                ZCRMUser CreatedBy = record11.CreatedBy;
                if (CreatedBy != null)
                {
                    Console.WriteLine(CreatedBy.Id);
                    Console.WriteLine(CreatedBy.FullName);
                }
                ZCRMUser ModifiedBy = record1.ModifiedBy;
                if (ModifiedBy != null)
                {
                    Console.WriteLine(ModifiedBy.Id);
                    Console.WriteLine(ModifiedBy.FullName);
                }
            }
        }
Пример #30
0
        public void UpdateInvestor(InvestorModel investor)
        {
            var id = dbzoho.tbl_CheckID.FirstOrDefault(p => p.EmailMS == investor.UserName);

            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            ZCRMRecord        record1      = new ZCRMRecord("accounts"); //module api name

            record1.EntityId = id.IDZoho;
            record1.SetFieldValue("id", id.IDZoho);
            record1.SetFieldValue("Account_Name", investor.UserName);
            record1.SetFieldValue("Email", investor.UserName);
            record1.SetFieldValue("Username", investor.UserName);
            record1.SetFieldValue("Industry", "1");
            record1.SetFieldValue("Status", "1");
            record1.SetFieldValue("Phone", investor.MobileNumber);
            record1.SetFieldValue("Fax", investor.MobileNumber);
            record1.SetFieldValue("Employees", 1);
            record1.SetFieldValue("Age", investor.Age);
            record1.SetFieldValue("Gender", investor.Gender);
            record1.SetFieldValue("NRIC_Number", investor.NRIC_Number);
            record1.SetFieldValue("Passport_Number", investor.PassportNumber);
            record1.SetFieldValue("Date_Of_Birth", investor.DateOfBirth.Value);
            record1.SetFieldValue("Sign_Up_Date", investor.DateCreated.Value.Date.ToString());
            record1.SetFieldValue("Total_Invested", investor.TotalInvestedAmount);
            record1.SetFieldValue("Admin_Verification", investor.AdminVerification);
            record1.SetFieldValue("Number_Of_Delinquent_Off_Note", investor.numofdelinquent);
            record1.SetFieldValue("Number_Of_Fully_Paid_Note", investor.NumberOfFullyPaidNotes);
            record1.SetFieldValue("Number_of_Close_Off_Note", investor.NumOfCloseOff);
            record1.SetFieldValue("Qualified_Date", investor.QualifiedDate.Value.Date.ToString());
            if (investor.LastLogin == null)
            {
                investor.LastLogin = investor.DateCreated;
            }
            record1.SetFieldValue("Number_Of_Deliquent_Note", investor.numofdelinquent);
            record1.SetFieldValue("Last_Login", investor.LastLogin.Value.Date.ToString());
            record1.SetFieldValue("Sum_of_Number_Invested_Note", investor.NumberOfInvested);
            record1.SetFieldValue("Current_in_Funding_Amount", investor.CurrentInFunding);
            record1.SetFieldValue("Sum_of_Ledge_Amount", investor.ActualAmount);
            record1.SetFieldValue("Total_Amount_Received", investor.TotalAmountReceived);
            record1.SetFieldValue("Total_Delinquent_Amount", investor.outstandingPI);
            record1.SetFieldValue("Outstanding_L", investor.outstanding_I);
            record1.SetFieldValue("Outstanding_P", investor.outstanding_P);
            record1.SetFieldValue("Principal_Received", investor.PaidP);
            record1.SetFieldValue("Interest_Received", investor.PaidI);
            records.Add(record1);


            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                   //module api name
            BulkAPIResponse <ZCRMRecord> responseIns = moduleIns.UpdateRecords(records); //To call the Update record method

            Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode);         //To get Update record http response code
            foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
            {
                Console.WriteLine("Status:" + response.Status);        //To get Update record response status
                Console.WriteLine("Message:" + response.Message);      //To get Update record response message
                Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
                ZCRMRecord record11 = (ZCRMRecord)response.Data;
                Console.WriteLine(record11.EntityId);                  //To get inserted record id
                Console.WriteLine(record11.CreatedTime);
                Console.WriteLine(record11.ModifiedTime);
                ZCRMUser CreatedBy = record11.CreatedBy;
                if (CreatedBy != null)
                {
                    Console.WriteLine(CreatedBy.Id);
                    Console.WriteLine(CreatedBy.FullName);
                }
                ZCRMUser ModifiedBy = record1.ModifiedBy;
                if (ModifiedBy != null)
                {
                    Console.WriteLine(ModifiedBy.Id);
                    Console.WriteLine(ModifiedBy.FullName);
                }
            }
        }