private ZCRMProfile GetZCRMProfile(JObject profileDetails) { ZCRMProfile profile = ZCRMProfile.GetInstance((long)profileDetails["id"], (string)profileDetails["name"]); profile.Category = (bool)profileDetails["category"]; profile.Description = (string)profileDetails["description"]; profile.CreatedBy = null; //TODO: Check with HasValues method; if (profileDetails["created_by"].Type != JTokenType.Null) { JObject createdByObject = (JObject)profileDetails["created_by"]; ZCRMUser createdBy = ZCRMUser.GetInstance((long)createdByObject["id"], (string)createdByObject["name"]); profile.CreatedBy = createdBy; profile.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(profileDetails["created_time"])); } profile.ModifiedBy = null; if (profileDetails["modified_by"].Type != JTokenType.Null) { JObject modifiedByObject = (JObject)profileDetails["modified_by"]; ZCRMUser modifiedBy = ZCRMUser.GetInstance((long)modifiedByObject["id"], (string)modifiedByObject["name"]); profile.ModifiedBy = modifiedBy; profile.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(profileDetails["modified_time"])); } return(profile); }
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)); } } }
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); }
public void GetAllModules() { ZCRMRestClient.Initialize(Dictionary.config); ZCRMRestClient restClient = ZCRMRestClient.GetInstance(); BulkAPIResponse <ZCRMModule> response = restClient.GetAllModules(); Console.WriteLine(response.HttpStatusCode); //Based on API Response List <ZCRMModule> modules = response.BulkData; // modules - list of ZCRMModule instances foreach (ZCRMModule module in modules) { Console.WriteLine(module.ApiName); Console.WriteLine(module.Id); Console.WriteLine(module.ModifiedTime); Console.WriteLine(module.PluralLabel); Console.WriteLine(module.SingularLabel); Console.WriteLine(module.SystemName); List <ZCRMProfile> AccessibleProfiles = module.AccessibleProfiles; foreach (ZCRMProfile profile in AccessibleProfiles) { Console.WriteLine(profile.Id); Console.WriteLine(profile.Name); } Console.WriteLine(module.ApiSupported); List <string> BussinessCardFields = module.BussinessCardFields; foreach (string BussinessCardField in BussinessCardFields) { Console.WriteLine(BussinessCardField); } Console.WriteLine(module.Convertable); Console.WriteLine(module.Creatable); Console.WriteLine(module.CustomModule); Console.WriteLine(module.Deletable); Console.WriteLine(module.Editable); ZCRMUser ModifiedBy = module.ModifiedBy; if (ModifiedBy != null) { Console.WriteLine(ModifiedBy.Id); Console.WriteLine(ModifiedBy.FullName); } List <ZCRMModuleRelation> relations = module.RelatedLists; foreach (ZCRMModuleRelation relation in relations) { Console.WriteLine(relation.ApiName); Console.WriteLine(relation.Id); } Console.WriteLine(module.Viewable); } }
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); }
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); } }
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); } } }
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); } }
/** Get list of records */ public void GetALLRecords() { Console.Clear(); try { ZCRMRestClient.Initialize(Dictionary.config); ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get module instance List <string> fields = new List <string>() { "Last_Name", "Company" }; BulkAPIResponse <ZCRMRecord> response = moduleIns.GetRecords(); //To get module records //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501); //Custom view Id of the module. //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(fields); //List of field API names //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, fields); //Custom view Id with List of field API names. //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501,1,10, fields); //Custom view Id, page, perPage and List of field API names. //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,fields); //Custom view Id, sortByField, sortOrder and List of field API names. //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,1,10, fields); //Custom view Id, sortByField, sortOrder, page, perPage and List of field API names. //BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00", fields); //Custom view Id, sortByField, sortOrder, page, perPage, modifiedSince(Header) and List of field API names. List <ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord. foreach (ZCRMRecord record in records) { Console.WriteLine(record.EntityId); //To get record id Console.WriteLine(record.ModuleAPIName); //To get module api name Console.WriteLine(record.LookupLabel); //To get lookup object name ZCRMUser createdBy = record.CreatedBy; Console.WriteLine(createdBy.Id); //To get UserId who created the record Console.WriteLine(createdBy.FullName); //To get User name who created the record ZCRMUser modifiedBy = record.ModifiedBy; Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record ZCRMUser owner = record.Owner; Console.WriteLine(owner.Id); //To get record OwnerId Console.WriteLine(owner.FullName); //To get record Owner name Console.WriteLine(record.CreatedTime); //To get record created time Console.WriteLine(record.ModifiedTime); //To get record modified time //Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value if (record.Tags.Count > 0) { foreach (ZCRMTag tagnames in record.Tags) { Console.WriteLine(tagnames.Id); Console.WriteLine(tagnames.Name); } Console.WriteLine("\n\n"); } Dictionary <string, object> recordData = record.Data; //Returns record as Dictionary //Console.WriteLine(record.PriceDetails); //foreach (KeyValuePair<string, object> data in record.Data) //{ // if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance // { // Console.WriteLine(recordValue.EntityId); //To get record id // Console.WriteLine(recordValue.ModuleAPIName); //To get module api name // Console.WriteLine(recordValue.LookupLabel); //To get lookup object name // } // else if (data.Value is List<string>) // { // Console.WriteLine(data.Key); // foreach (string tag in (List<string>)data.Value) // { // Console.WriteLine(tag); // } // Console.WriteLine("\n\n"); // } // else //data.Value is not ZCRMRecord instance // { // Console.WriteLine(data.Key + "\t" + data.Value); // } //} Console.WriteLine("\n\n"); /** Fields which start with "$" are considered to be property fields */ //Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value Dictionary <string, object> properties = record.Properties; //To get record properties as Dictionary foreach (KeyValuePair <string, object> property in properties) { if (property.Value is List <string> ) //If value is an array { Console.WriteLine("\n\n" + property.Key); foreach (string data in (List <string>)property.Value) { Console.WriteLine(data + "\t"); } } else if (property.Value is Dictionary <string, object> ) { Console.WriteLine("\n\n" + property.Key); foreach (KeyValuePair <string, object> data in (Dictionary <string, object>)property.Value) { if (property.Value is Dictionary <string, object> ) { foreach (KeyValuePair <string, object> data1 in (Dictionary <string, object>)data.Value) { Console.WriteLine(data1.Key + "\t" + data1.Value); } } else { Console.WriteLine(data.Key + "\t" + data.Value); } } } else { Console.WriteLine(property.Key + "\t" + property.Value); } } //To get Related records of a record BulkAPIResponse <ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); /** Related records is of type ZCRMRecord **/ List <ZCRMRecord> lists = relatedlist.BulkData; //To get related list data foreach (ZCRMRecord rec in lists) { Console.WriteLine(rec.EntityId); //To get record id Console.WriteLine(rec.ModuleAPIName); //To get module api name } //To get record notes BulkAPIResponse <ZCRMNote> noteResponse = record.GetNotes(); //BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage. //BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder //BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header) List <ZCRMNote> notes = noteResponse.BulkData; foreach (ZCRMNote note in notes) { Console.WriteLine(note.Id); //To get note id Console.WriteLine(note.Title); //To get note title Console.WriteLine(note.Content); //To get note content ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record Console.WriteLine(parentRecord.EntityId); //To get note's parent record id Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name ZCRMUser noteCreatedBy = note.CreatedBy; Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes ZCRMUser noteModifiedBy = note.ModifiedBy; Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes ZCRMUser noteOwner = note.NotesOwner; Console.WriteLine(noteOwner.Id); //To get notes OwnerId Console.WriteLine(noteOwner.FullName); //To get notes Owner name Console.WriteLine(note.CreatedTime); //To get created time of the note Console.WriteLine(note.ModifiedTime); //To get modified time of the note List <ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record if (noteAttachment != null) //check If attachments is empty/not { foreach (ZCRMAttachment attachment in noteAttachment) { Console.WriteLine(attachment.Id); //To get the note's attachment id Console.WriteLine(attachment.FileName); //To get the note's attachment file name Console.WriteLine(attachment.FileType); //To get the note's attachment file type Console.WriteLine(attachment.Size); //To get the note's attachment file size ZCRMRecord attachmentRecord = attachment.ParentRecord; Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name ZCRMUser noteAttachmentCreatedBy = note.CreatedBy; Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy; Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment ZCRMUser noteAttachmentOwner = note.NotesOwner; Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name Console.WriteLine(attachment.CreatedTime); //To get attachment created time Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time } } } //To get record's attachments BulkAPIResponse <ZCRMAttachment> attachmentResponse = record.GetAttachments(); //BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header) // To get list of attachments List <ZCRMAttachment> attachments = attachmentResponse.BulkData; foreach (ZCRMAttachment attachment in attachments) { Console.WriteLine(attachment.Id); //To get the attachment id Console.WriteLine(attachment.FileName); //To get attachment file name Console.WriteLine(attachment.FileType); // To get attachment file type Console.WriteLine(attachment.Size); //To get attachment file size ZCRMRecord attachmentRecord = attachment.ParentRecord; Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name ZCRMUser attachmentCreatedBy = attachment.CreatedBy; Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment ZCRMUser attachmentModifiedBy = attachment.ModifiedBy; Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment ZCRMUser noteAttachmentOwner = attachment.Owner; Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name Console.WriteLine(attachment.CreatedTime); //To get attachment created time Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time //FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file //Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name //Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code //Stream file = fResponse.GetFileAsStream(); //To get attachment file content //CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name } ZCRMLayout layout = record.Layout; //To get record layout if (layout != null) { Console.WriteLine(layout.Id); //To get layout_id Console.WriteLine(layout.Name); //To get layout name } /** Following methods are being used only by Inventory modules */ List <ZCRMTax> taxlists = record.TaxList; //To get the tax list foreach (ZCRMTax tax in taxlists) { Console.WriteLine(tax.TaxName); //To get tax name Console.WriteLine(tax.Percentage); //To get tax percentage Console.WriteLine(tax.Value); //To get tax value } List <ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items foreach (ZCRMInventoryLineItem lineItem in lineItems) { Console.WriteLine(lineItem.Id); //To get lineItem id Console.WriteLine(lineItem.ListPrice); //To get lineItem list price Console.WriteLine(lineItem.Quantity); //To get lineItem quantity Console.WriteLine(lineItem.Description); //To get lineItem description Console.WriteLine(lineItem.Total); //To get lineItem total amount Console.WriteLine(lineItem.Discount); //To get lineItem discount Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label List <ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem foreach (ZCRMTax tax in linetaxs) { Console.WriteLine(tax.TaxName); //To get line tax name Console.WriteLine(tax.Percentage); //To get line tax percentage Console.WriteLine(tax.Value); //To get line tax value } } List <ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array foreach (ZCRMPriceBookPricing pricedetail in pricedetails) { Console.WriteLine(pricedetail.Id); //To get the record's priceId Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount } /** End Inventory **/ /** Following method is used only by 'Events' module */ List <ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants foreach (ZCRMEventParticipant participant in participants) { Console.WriteLine(participant.Id); //To get the record's participant id Console.WriteLine(participant.Name); //To get the record's participant name Console.WriteLine(participant.Email); //To get the record's participant email Console.WriteLine(participant.Type); //To get the record's participant type Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not Console.WriteLine(participant.Status); //To get the record's participants' status } /* End Event */ } //Console.WriteLine("Headers"+response.GetResponseHeaders()); BulkAPIResponse <ZCRMRecord> .ResponseInfo info = response.Info; Console.WriteLine(info.AllowedCount); Console.WriteLine(info.MoreRecords); Console.WriteLine(info.PageNo); Console.WriteLine(info.PerPage); Console.WriteLine(info.RecordCount); Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute); Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow); Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset); } catch (ZCRMException ex) { Console.WriteLine(ex.Message); //To get ZCRMException error message Console.WriteLine(ex.Source); //To get ZCRMException error source Console.WriteLine(ex.StackTrace); //To get ZCRMException stack trace } }
/// <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)); }
/// <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 ZCRMModule GetZCRMModule(JObject moduleDetails) { try { ZCRMModule module = ZCRMModule.GetInstance((string)moduleDetails["api_name"]); module.Id = Convert.ToInt64(moduleDetails["id"]); module.SystemName = (string)moduleDetails["module_name"]; module.SingularLabel = (string)moduleDetails["singular_label"]; module.PluralLabel = (string)moduleDetails["plural_label"]; module.Creatable = (bool)moduleDetails["creatable"]; module.Viewable = (bool)moduleDetails["viewable"]; module.Editable = (bool)moduleDetails["editable"]; module.Convertable = (bool)moduleDetails["convertable"]; module.Deletable = (bool)moduleDetails["deletable"]; module.CustomModule = (bool)(moduleDetails["generated_type"].ToString().Equals("custom")); module.ApiSupported = (bool)(moduleDetails["api_supported"]); JArray accessibleProfilesArray = (JArray)moduleDetails["profiles"]; foreach (JObject accessibleProfiles in accessibleProfilesArray) { ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles["id"]), (string)accessibleProfiles["name"]); module.AddAccessibleProfile(profile); } if (moduleDetails["modified_by"].HasValues) { JObject modifiedByObject = (JObject)moduleDetails["modified_by"]; ZCRMUser modifiedUser = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]); module.ModifiedBy = modifiedUser; module.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(moduleDetails["modified_time"])); } if (moduleDetails.ContainsKey("related_lists") && moduleDetails["related_lists"].Type != JTokenType.Null) { List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>(); JArray relatedListsArray = (JArray)moduleDetails["related_lists"]; foreach (JObject relatedListDetails in relatedListsArray) { ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, (string)relatedListDetails["api_name"]); SetRelatedListProperties(relatedList, relatedListDetails); relatedLists.Add(relatedList); } module.RelatedLists = relatedLists; } if (moduleDetails.ContainsKey("business_card_fields") && moduleDetails.Type != JTokenType.Null) { List <string> bcFields = new List <string>(); JArray bcFieldsArray = (JArray)moduleDetails["business_card_fields"]; foreach (JObject bcField in bcFieldsArray) { bcFields.Add(bcField.ToString()); } module.BussinessCardFields = bcFields; } if (moduleDetails.ContainsKey("layouts")) { module.Layouts = ModuleAPIHandler.GetInstance(module).GetAllLayouts(moduleDetails); } return(module); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
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); } } } }
private ZCRMLayout GetZCRMLayout(JObject layoutDetails) { ZCRMLayout layout = ZCRMLayout.GetInstance(Convert.ToInt64(layoutDetails["id"])); layout.Name = Convert.ToString(layoutDetails["name"]); layout.Visible = Convert.ToBoolean(layoutDetails["visible"]); layout.Status = Convert.ToInt32(layoutDetails["status"]); if (layoutDetails["created_by"].HasValues) { JObject createdByObject = (JObject)layoutDetails["created_by"]; ZCRMUser createdUser = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), Convert.ToString(createdByObject["name"])); layout.CreatedBy = createdUser; layout.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(layoutDetails["created_time"])); } if (layoutDetails["modified_by"].HasValues) { JObject modifiedByObject = (JObject)layoutDetails["modified_by"]; ZCRMUser modifiedUser = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), Convert.ToString(modifiedByObject["name"])); layout.ModifiedBy = modifiedUser; layout.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(layoutDetails["modified_time"])); } JArray accessibleProfilesArray = (JArray)layoutDetails["profiles"]; foreach (JObject profileObject in accessibleProfilesArray) { ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(profileObject["id"]), Convert.ToString(profileObject["name"])); if (profileObject.ContainsKey("default") && profileObject["default"].Type != JTokenType.Null) { profile.IsDefault = Convert.ToBoolean(profileObject["default"]); } layout.AddAccessibleProfiles(profile); } layout.Sections = GetAllSectionsofLayout(layoutDetails); if (layoutDetails.ContainsKey("convert_mapping") && layoutDetails["convert_mapping"].Type != JTokenType.Null) { List <string> convertModules = new List <string>() { "Contacts", "Deals", "Accounts" }; Dictionary <string, ZCRMLeadConvertMapping> convertMapDic = new Dictionary <string, ZCRMLeadConvertMapping>(); foreach (string convertModule in convertModules) { if (((JObject)layoutDetails["convert_mapping"]).ContainsKey(convertModule) && ((JObject)layoutDetails["convert_mapping"])[convertModule].Type != JTokenType.Null) { JObject contactsMap = (JObject)layoutDetails["convert_mapping"][convertModule]; ZCRMLeadConvertMapping convertMapIns = ZCRMLeadConvertMapping.GetInstance(contactsMap["name"].ToString(), Convert.ToInt64(contactsMap["id"])); if (contactsMap.ContainsKey("fields") && contactsMap["fields"].Type != JTokenType.Null) { List <ZCRMLeadConvertMappingField> ConvertMappingFields = new List <ZCRMLeadConvertMappingField>(); JArray fields = (JArray)contactsMap["fields"]; foreach (JObject field in fields) { ZCRMLeadConvertMappingField convertMappingFieldIns = ZCRMLeadConvertMappingField.GetInstance(field["api_name"].ToString(), Convert.ToInt64(field["id"])); convertMappingFieldIns.FieldLabel = field["field_label"].ToString(); convertMappingFieldIns.Required = Convert.ToBoolean(field["required"]); ConvertMappingFields.Add(convertMappingFieldIns); } convertMapIns.Fields = ConvertMappingFields; } convertMapDic.Add(convertModule, convertMapIns); } } layout.ConvertMapping = convertMapDic; } return(layout); }
private ZCRMAttachment GetZCRMAttachment(JObject attachmentDetails) { ZCRMAttachment attachment = ZCRMAttachment.GetInstance(parentRecord, Convert.ToInt64(attachmentDetails["id"])); string fileName = (string)attachmentDetails["File_Name"]; if (fileName != null) { attachment.FileName = fileName; attachment.FileType = fileName.Substring(fileName.LastIndexOf('.') + 1); } if (attachmentDetails.ContainsKey("Size")) { attachment.Size = Convert.ToInt64(attachmentDetails["Size"]); } if (attachmentDetails.ContainsKey("Created_By") && attachmentDetails["Created_By"].Type != JTokenType.Null) { JObject createdByObject = (JObject)attachmentDetails["Created_By"]; ZCRMUser createdBy = ZCRMUser.GetInstance(Convert.ToInt64(createdByObject["id"]), (string)createdByObject["name"]); attachment.CreatedBy = createdBy; attachment.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(attachmentDetails["Created_Time"])); if (attachmentDetails["Owner"] != null && attachmentDetails["Owner"].Type != JTokenType.Null) { JObject ownerObject = (JObject)attachmentDetails["Owner"]; ZCRMUser owner = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject["id"]), (string)ownerObject["name"]); attachment.Owner = owner; } else { attachment.Owner = createdBy; } } if (attachmentDetails.ContainsKey("Modified_By") && attachmentDetails["Modified_By"].Type != JTokenType.Null) { JObject modifiedByObject = (JObject)attachmentDetails["Modified_By"]; ZCRMUser modifiedBy = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]); attachment.ModifiedBy = modifiedBy; attachment.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(attachmentDetails["Modified_Time"])); } if (attachmentDetails.ContainsKey("$editable")) { if (attachmentDetails["$editable"] != null) { attachment.Editable = Convert.ToBoolean(attachmentDetails["$editable"]); } } if (attachmentDetails.ContainsKey("$file_id")) { if (attachmentDetails["$file_id"] != null) { attachment.FieldId = Convert.ToString(attachmentDetails["$file_id"]); } } if (attachmentDetails.ContainsKey("$type")) { if (attachmentDetails["$type"] != null) { attachment.Type = Convert.ToString(attachmentDetails["$type"]); } } if (attachmentDetails.ContainsKey("$se_module")) { if (attachmentDetails["$se_module"] != null) { attachment.Se_module = Convert.ToString(attachmentDetails["$se_module"]); } } if (attachmentDetails.ContainsKey("$link_url")) { if (attachmentDetails["$link_url"] != null) { attachment.Link_url = Convert.ToString(attachmentDetails["$link_url"]); } } return(attachment); }
/** To get All Users */ public void GetAllUsers() { ZCRMRestClient restClient = ZCRMRestClient.GetInstance(); BulkAPIResponse <ZCRMUser> response = restClient.GetOrganizationInstance().GetAllUsers(); List <ZCRMUser> allUsers = response.BulkData; // users - list of ZCRMUser instances foreach (ZCRMUser user in allUsers) { Console.WriteLine(user.Country); ZCRMRole Role = user.Role; if (Role != null) { Console.WriteLine(Role.Id); Console.WriteLine(Role.Name); } if (user.CustomizeInfo != null) { ZCRMUserCustomizeInfo customizeInfo = user.CustomizeInfo; Console.WriteLine(customizeInfo.NotesDesc); Console.WriteLine(customizeInfo.IsToShowRightPanel); Console.WriteLine(customizeInfo.IsBcView); Console.WriteLine(customizeInfo.IsToShowHome); Console.WriteLine(customizeInfo.IsToShowDetailView); Console.WriteLine(customizeInfo.UnpinRecentItem); } Console.WriteLine(user.City); Console.WriteLine(user.Signature); Console.WriteLine(user.NameFormat); Console.WriteLine(user.Language); Console.WriteLine(user.Locale); Console.WriteLine(user.MicrosoftAppUser); Console.WriteLine(user.IsPersonalAccount); Console.WriteLine(user.IsOnline); Console.WriteLine(user.DefaultTabGroup); ZCRMUser ModifiedBy = user.ModifiedBy; if (ModifiedBy != null) { Console.WriteLine(ModifiedBy.Id); Console.WriteLine(ModifiedBy.FullName); } Console.WriteLine(user.Number); Console.WriteLine(user.Street); Console.WriteLine(user.Alias); if (user.Theme != null) { ZCRMUserTheme theme = user.Theme; Console.WriteLine(theme.NormalTabFontColor); Console.WriteLine(theme.NormalTabBackground); Console.WriteLine(theme.SelectedTabFontColor); Console.WriteLine(theme.SelectedTabBackground); Console.WriteLine(theme.New_background); Console.WriteLine(theme.Background); Console.WriteLine(theme.Screen); Console.WriteLine(theme.Type); } Console.WriteLine(user.Id); Console.WriteLine(user.State); Console.WriteLine(user.Fax); Console.WriteLine(user.CountryLocale); Console.WriteLine(user.FirstName); Console.WriteLine(user.EmailId); ZCRMUser ReportingTo = user.ReportingTo; if (ReportingTo != null) { Console.WriteLine(ReportingTo.Id); Console.WriteLine(ReportingTo.FullName); } Console.WriteLine(user.Zip); Console.WriteLine(user.DecimalSeparator); Console.WriteLine(user.CreatedTime); Console.WriteLine(user.ModifiedTime); Console.WriteLine(user.Website); Console.WriteLine(user.TimeFormat); Console.WriteLine(user.OffSet); ZCRMProfile Profile = user.Profile; if (Profile != null) { Console.WriteLine(Profile.Id); Console.WriteLine(Profile.Name); } Console.WriteLine(user.Mobile); Console.WriteLine(user.LastName); Console.WriteLine(user.TimeZone); ZCRMUser CreatedBy = user.CreatedBy; if (CreatedBy != null) { Console.WriteLine(CreatedBy.Id); Console.WriteLine(CreatedBy.FullName); } Console.WriteLine(user.ZuId); Console.WriteLine(user.Confirm); Console.WriteLine(user.FullName); if (user.Territories != null && user.Territories.Count > 0) { foreach (ZCRMTerritory territory in user.Territories) { Console.WriteLine(territory.IsManager); Console.WriteLine(territory.Name); Console.WriteLine(territory.Id); } } Console.WriteLine(user.Phone); Console.WriteLine(user.DateOfBirth); Console.WriteLine(user.DateFormat); Console.WriteLine(user.Status); } }
private ZCRMUser GetZCRMUser(JObject userDetails) { ZCRMUser user = ZCRMUser.GetInstance((long)userDetails["id"], (string)userDetails["full_name"]); user.EmailId = (string)userDetails["email"]; user.FirstName = (string)userDetails["first_name"]; user.LastName = (string)userDetails["last_name"]; user.Language = (string)userDetails["language"]; user.Mobile = (string)userDetails["mobile"]; user.Status = (string)userDetails["status"]; user.ZuId = (long?)userDetails["zuid"]; if (userDetails.ContainsKey("profile")) { JObject profileObject = (JObject)userDetails["profile"]; ZCRMProfile profile = ZCRMProfile.GetInstance((long)profileObject["id"], (string)profileObject["name"]); user.Profile = profile; } if (userDetails.ContainsKey("role")) { JObject roleObject = (JObject)userDetails["role"]; ZCRMRole role = ZCRMRole.GetInstance((long)roleObject["id"], (string)roleObject["name"]); user.Role = role; } user.Alias = (string)userDetails["alias"]; user.City = (string)userDetails["city"]; user.Confirm = (bool)userDetails["confirm"]; user.CountryLocale = (string)userDetails["country_locale"]; user.DateFormat = (string)userDetails["date_format"]; user.TimeFormat = (string)userDetails["time_format"]; user.DateOfBirth = (string)userDetails["dob"]; user.Country = (string)userDetails["country"]; user.Fax = (string)userDetails["fax"]; user.Locale = (string)userDetails["locale"]; user.NameFormat = (string)userDetails["name_format"]; user.Website = (string)userDetails["website"]; user.TimeZone = (string)userDetails["time_zone"]; user.Street = (string)userDetails["street"]; user.State = (string)userDetails["state"]; user.MicrosoftAppUser = (bool)userDetails["microsoft"]; user.Phone = (string)userDetails["phone"]; if (userDetails.ContainsKey("created_by") && userDetails["created_by"].Type != JTokenType.Null) { JObject createdByObject = (JObject)userDetails["created_by"]; ZCRMUser createdUser = ZCRMUser.GetInstance((long)createdByObject["id"], (string)createdByObject["name"]); user.CreatedBy = createdUser; user.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(userDetails["created_time"])); } if (userDetails.ContainsKey("Modified_By") && userDetails["Modified_By"].Type != JTokenType.Null) { JObject modifiedByObject = (JObject)userDetails["Modified_By"]; ZCRMUser modifiedByUser = ZCRMUser.GetInstance((long)modifiedByObject["id"], (string)modifiedByObject["name"]); user.ModifiedBy = modifiedByUser; user.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(userDetails["Modified_Time"])); } if (userDetails.ContainsKey("Reporting_To") && userDetails["Reporting_To"].Type != JTokenType.Null) { JObject reportingToObject = (JObject)userDetails["Reporting_To"]; ZCRMUser reportingTo = ZCRMUser.GetInstance((long)reportingToObject["id"], (string)reportingToObject["name"]); user.ReportingTo = reportingTo; } if (userDetails.ContainsKey("signature") && userDetails["signature"].Type != JTokenType.Null) { user.Signature = (string)userDetails["signature"]; } if (userDetails.ContainsKey("number") && userDetails["number"].Type != JTokenType.Null) { user.Number = (int)userDetails["number"]; } if (userDetails.ContainsKey("offset") && userDetails["offset"].Type != JTokenType.Null) { user.OffSet = (long)userDetails["offset"]; } if (userDetails.ContainsKey("customize_info") && userDetails["customize_info"].Type != JTokenType.Null) { user.CustomizeInfo = GetZCRMUserCustomizeInfo((JObject)userDetails["customize_info"]); } if (userDetails.ContainsKey("personal_account") && userDetails["personal_account"].Type != JTokenType.Null) { user.IsPersonalAccount = (bool)userDetails["personal_account"]; } if (userDetails.ContainsKey("default_tab_group") && userDetails["default_tab_group"].Type != JTokenType.Null) { user.DefaultTabGroup = (string)userDetails["default_tab_group"]; } if (userDetails.ContainsKey("theme") && userDetails["theme"].Type != JTokenType.Null) { user.Theme = GetZCRMUserTheme((JObject)userDetails["theme"]); } if (userDetails.ContainsKey("zip") && userDetails["zip"].Type != JTokenType.Null) { user.Zip = (string)userDetails["zip"]; } if (userDetails.ContainsKey("decimal_separator") && userDetails["decimal_separator"].Type != JTokenType.Null) { user.DecimalSeparator = (string)userDetails["decimal_separator"]; } if (userDetails.ContainsKey("territories") && userDetails["territories"].Type != JTokenType.Null) { JArray jsonArray = (JArray)userDetails["territories"]; List <ZCRMTerritory> territories = new List <ZCRMTerritory>(); foreach (JObject territory in jsonArray) { territories.Add(GetZCRMTerritory(territory)); } user.Territories = territories; } if (userDetails.ContainsKey("Isonline") && userDetails["Isonline"].Type != JTokenType.Null) { user.IsOnline = (bool)userDetails["Isonline"]; } if (userDetails.ContainsKey("Currency") && userDetails["Currency"].Type != JTokenType.Null) { user.Currency = (string)userDetails["Currency"]; } foreach (KeyValuePair <string, JToken> token in userDetails) { if (!ZCRMUser.defaultKeys.Contains(token.Key)) { user.SetFieldValue(token.Key, (object)token.Value); } } return(user); }
private 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); }