public APIResponse UpdateNote(ZCRMNote note) { try { requestMethod = APIConstants.RequestMethod.PUT; urlPath = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName + "/" + note.Id; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); dataArray.Add(GetZCRMNoteAsJSON(note)); requestBodyObject.Add(APIConstants.DATA, dataArray); requestBody = requestBodyObject; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); JArray responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA]; JObject responseData = (JObject)responseDataArray[0]; JObject responseDetails = (JObject)responseData[APIConstants.DETAILS]; note = GetZCRMNote(responseDetails, note); response.Data = note; return(response); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
public APIResponse UpdateNote(ZCRMNote note) { try { requestMethod = APIConstants.RequestMethod.PUT; urlPath = $"{parentRecord.ModuleAPIName}/{parentRecord.EntityId}/{relatedList.ApiName}"; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); dataArray.Add(GetZCRMNoteAsJSON(note)); requestBodyObject.Add("data", dataArray); requestBody = requestBodyObject; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); JArray responseDataArray = (JArray)response.ResponseJSON.GetValue("data"); JObject responseData = (JObject)responseDataArray[0]; JObject responseDetails = (JObject)responseData.GetValue("details"); note = GetZCRMNote(responseDetails, note); response.Data = note; return(response); } catch (Exception e) { //TODO: Log the exception; Console.WriteLine("Exception in Updatenote"); Console.WriteLine(e); throw new ZCRMException("ZCRM_INTERNAL_ERROR"); } }
public APIResponse DeleteNote(ZCRMNote note) { requestMethod = APIConstants.RequestMethod.DELETE; urlPath = $"{parentRecord.ModuleAPIName}/{parentRecord.EntityId}/{relatedList.ApiName}/{note.Id}"; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); return(response); }
public APIResponse DeleteNote(ZCRMNote note) { try { requestMethod = APIConstants.RequestMethod.DELETE; urlPath = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName + "/" + note.Id; return(APIRequest.GetInstance(this).GetAPIResponse()); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
private void PopulateTradeInNote(TradeInDetails tradein, ZCRMNote note) { string details = string.Join(Environment.NewLine, new string[] { $"Make: {tradein.Make}", $"Model: {tradein.Model}", $"Year: {tradein.Year}", $"Mileage: {tradein.Mileage}", $"Condition: {tradein.Condition}", $"Amount Owed: {tradein.AmountOwed:C2}", }); note.Title = $"Trade-In Details {DateTime.Now:g}"; note.Content = details; }
private JObject GetZCRMNoteAsJSON(ZCRMNote note) { JObject noteJSON = new JObject(); if (note.Title != null) { noteJSON.Add("Note_Title", note.Title); } else { noteJSON.Add("Note_Title", null); } noteJSON.Add("Note_Content", note.Content); return(noteJSON); }
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); }
private void PopulateFinancingNote(FinancingDetails financing, ZCRMNote note) { var lines = financing.GoodCredit ? new string[] { $"Credit Score: {financing.CreditScore}" } : new string[] { $"Credit Score: {financing.CreditScore}", $"Income: {financing.Income}", $"Home Ownership: {financing.HomeOwnership}", $"Employment History: {financing.Employment}", }; note.Title = $"Financing Details {DateTime.Now:g}"; note.Content = string.Join(Environment.NewLine, lines); }
private void PopulateInventoryNote(VehicleInventoryDetails inventory, ZCRMNote note) { List <string> lines = new List <string>(); lines.Add($"Primary Concern: {inventory.PrimaryConcern}"); lines.Add($"Looking for"); lines.Add($"Make: {inventory.Make}"); lines.Add($"Model: {inventory.Model}"); lines.Add($"Color: {inventory.Color}"); lines.Add($"Min Price: {inventory.MinPrice:C2}"); lines.Add($"Max Price: {inventory.MaxPrice:C2}"); string details = string.Join(Environment.NewLine, new string[] { $"Goal: {inventory.Make}" }); note.Title = $"Inventory Inquiry {DateTime.Now:g}"; note.Content = details; }
private bool CreateAndPopulateNote <T>(UserProfile profile, T UserData, Action <T, ZCRMNote> PopulateNoteFunction) where T : IADSCRMRecord { if (!Connected) { return(false); } if (!profile.ADS_CRM_ID.HasValue) { throw new Exception("Profile does not have a registered CRM ID"); } var leadRecord = ZCRMRecord.GetInstance("Leads", profile.ADS_CRM_ID); if (UserData != null && UserData.ADS_CRM_ID == null) { var newExistingNote = UserData.ADS_CRM_ID == null ? new ZCRMNote(leadRecord) : ZCRMNote.GetInstance(leadRecord, UserData.ADS_CRM_ID.Value); PopulateNoteFunction(UserData, newExistingNote); if (UserData.ADS_CRM_ID == null) { var createdNote = leadRecord.AddNote(newExistingNote); if (createdNote.HttpStatusCode != APIConstants.ResponseCode.CREATED) { throw new Exception("Failed to create note for lead."); } UserData.ADS_CRM_ID = (createdNote.Data as ZCRMNote).Id; } else { var updatedNote = leadRecord.UpdateNote(newExistingNote); if (updatedNote.HttpStatusCode != APIConstants.ResponseCode.OK) { throw new Exception("Failed to update note for lead."); } } } return(false); }
private void PopulateVehicleProfileNote(VehicleProfileDetails vehicleProfile, ZCRMNote note) { string details = string.Join(Environment.NewLine, new string[] { $"Needs Financing: {((vehicleProfile.NeedFinancing ?? false) ? "Yes" : "No")}", $"Trading-In: {((vehicleProfile.TradingIn ?? false) ? "Yes" : "No")}", $"", $"Make: {vehicleProfile.Make}", $"Model: {vehicleProfile.Model}", $"Year: {vehicleProfile.Year}", $"Color: {vehicleProfile.Color}" }); note.Title = $"Vehilcle Profile Details {DateTime.Now:g}"; note.Content = details; }