public ActionResult <string> Get(string statement) { if (string.IsNullOrEmpty(statement)) { return(string.Empty); } if (Request.QueryString.Value.IndexOf("&") > 0) { var filters = Request.QueryString.Value.Substring(Request.QueryString.Value.IndexOf("&") + 1); statement = $"{statement}?{filters}"; } var response = new Dyn365WebAPI().SendRetrieveRequestAsync(statement, true); if (response.IsSuccessStatusCode) { return(Ok(response.Content.ReadAsStringAsync().Result)); } else { return(StatusCode((int)response.StatusCode, $"Failed to Retrieve records: {response.ReasonPhrase}")); } }
public ActionResult <string> Post(string statement, [FromBody] dynamic value) { var response = new Dyn365WebAPI().SendCreateRequestAsync(statement, value.ToString()); //TODO: Improve Exception handling if (response.IsSuccessStatusCode) { var entityUri = response.Headers.GetValues("OData-EntityId")[0]; string pattern = @"(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}"; Match m = Regex.Match(entityUri, pattern, RegexOptions.IgnoreCase); var newRecordId = string.Empty; if (m.Success) { newRecordId = m.Value; return(Ok($"{newRecordId}")); } else { return(StatusCode((int)HttpStatusCode.InternalServerError, "Unable to create record at this time")); } } else { return(StatusCode((int)response.StatusCode, $"Failed to Create record: {response.ReasonPhrase}")); } }
public ActionResult <string> GetFile(string annotationId) { if (string.IsNullOrEmpty(annotationId)) { return(string.Empty); } string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='annotation' > <attribute name='filename' /> <attribute name='filesize' /> <attribute name='notetext' /> <attribute name='documentbody' /> <filter> <condition attribute='annotationid' operator='eq' value= '{" + annotationId + @"}' /> </filter> </entity> </fetch>"; var statement = $"annotations?fetchXml=" + WebUtility.UrlEncode(fetchXML); var response = new Dyn365WebAPI().SendRetrieveRequestAsync(statement, true); if (response.IsSuccessStatusCode) { return(Ok(response.Content.ReadAsStringAsync().Result)); } else { return(StatusCode((int)response.StatusCode, $"Failed to Retrieve records: {response.ReasonPhrase}")); } }
public ActionResult <string> UploadFile([FromBody] dynamic value) { var rawJsonData = value.ToString(); // stop, if the file size exceeds 3mb if (rawJsonData.Length > 3999999) { return(StatusCode((int)HttpStatusCode.InternalServerError, "The file size exceeds the limit allowed (<3Mb).")); } ; JObject obj = JObject.Parse(rawJsonData); obj.Add("notetext", JToken.FromObject(new string("Uploaded Document"))); rawJsonData = obj.ToString(); string filename = (string)obj["filename"]; string[] partialfilename = filename.Split('.'); string fileextension = partialfilename[partialfilename.Count() - 1].ToLower(); // stop, if the file format whether is not JPG, PDF or PNG string[] acceptedFileFormats = { "jpg", "jpeg", "pdf", "png" }; if (Array.IndexOf(acceptedFileFormats, fileextension) == -1) { return(StatusCode((int)HttpStatusCode.InternalServerError, "Sorry, only PDF, JPG and PNG file formats are supported.")); } var response = new Dyn365WebAPI().SendCreateRequestAsync("annotations", rawJsonData); //TODO: Improve Exception handling if (response.IsSuccessStatusCode) { var entityUri = response.Headers.GetValues("OData-EntityId")[0]; string pattern = @"(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}"; Match m = Regex.Match(entityUri, pattern, RegexOptions.IgnoreCase); var newRecordId = string.Empty; if (m.Success) { newRecordId = m.Value; return(Ok($"{newRecordId}")); } else { return(StatusCode((int)HttpStatusCode.InternalServerError, "Unable to create record at this time")); } } else { return(StatusCode((int)response.StatusCode, $"Failed to Create record: {response.ReasonPhrase}")); } }
public ActionResult <string> Delete(string statement) { var response = new Dyn365WebAPI().SendDeleteRequestAsync(statement); //TODO: Improve Exception handling if (response.IsSuccessStatusCode) { return(Ok($"{statement} removed")); } else { return(StatusCode((int)response.StatusCode, response.Content.ToString())); } }
public ActionResult <string> Patch(string statement, [FromBody] dynamic value) { HttpResponseMessage response = new Dyn365WebAPI().SendUpdateRequestAsync(statement, value.ToString()); //TODO: Improve Exception handling if (response.IsSuccessStatusCode) { return(Ok($"{value.ToString()}")); } else { return(StatusCode((int)response.StatusCode, $"Failed to Update record: {response.ReasonPhrase}")); } }
public ActionResult <string> RemoveFile(string annotationid) { annotationid = "annotations(" + annotationid + ")"; var response = new Dyn365WebAPI().SendDeleteRequestAsync(annotationid); if (response.IsSuccessStatusCode) { return(Ok("The contract has been removed")); } else { return(StatusCode((int)response.StatusCode, $"Failed to remove the contract: {response.ReasonPhrase}")); } }
public ActionResult <string> Post(string name, [FromBody] dynamic value) { var response = new Dyn365WebAPI().SendCreateRequestAsync(name, value.ToString()); //TODO: Improve Exception handling if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; return(Ok($"{result}")); } else { return(StatusCode((int)response.StatusCode, $"Failed to Create record: {response.ReasonPhrase}")); } }
public ActionResult <string> Get(string contactId) { if (string.IsNullOrEmpty(contactId)) { return(string.Empty); } string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='educ_assignment'> <attribute name='educ_assignmentid' /> <attribute name='educ_contractstage' /> <order descending='false' attribute='educ_contact' /> <filter type='and'> <filter type='or'> <condition attribute='statuscode' operator='eq' value='610410002' /> <condition attribute='statuscode' operator='eq' value='610410003' /> </filter> <condition attribute='statecode' operator='eq' value='0' /> <condition attribute='educ_contact' operator='eq' value='{" + contactId + @"}' /> </filter> <link-entity name='educ_session' from='educ_sessionid' to='educ_session' visible='false' link-type='outer' alias='session'> <attribute name='educ_startdate' alias='startDate' /> <attribute name='educ_enddate' alias='endDate'/> <attribute name='educ_sessiontype' alias='sessionType' /> <attribute name='educ_locationcity' alias='locationCity'/> </link-entity> </entity> </fetch>"; var statement = $"educ_assignments?fetchXml=" + WebUtility.UrlEncode(fetchXML); var response = new Dyn365WebAPI().SendRetrieveRequestAsync(statement, true); if (response.IsSuccessStatusCode) { return(Ok(response.Content.ReadAsStringAsync().Result)); } else { return(StatusCode((int)response.StatusCode, $"Failed to Retrieve records: {response.ReasonPhrase}")); } }
public ActionResult <string> Get(string entityName, string optionSetName) { if (string.IsNullOrEmpty(entityName) || string.IsNullOrEmpty(optionSetName)) { return(string.Empty); } var statement = string.Empty; if (optionSetName.ToLower() != "statuscode") { statement = $"EntityDefinitions(LogicalName='{entityName}')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '{optionSetName}'&$expand=OptionSet"; } else { statement = $"EntityDefinitions(LogicalName='{entityName}')/Attributes/Microsoft.Dynamics.CRM.StatusAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '{optionSetName}'&$expand=OptionSet"; } var response = new Dyn365WebAPI().SendRetrieveRequestAsync(statement, true); if (response.IsSuccessStatusCode) { JObject metadataInfo = JObject.Parse(response.Content.ReadAsStringAsync().Result); Dynamics365OptionSet optionSet = new Dynamics365OptionSet { InternalName = metadataInfo["value"][0]["OptionSet"]["Name"].ToString(), LogicalName = metadataInfo["value"][0]["LogicalName"].ToString(), Options = (from o in metadataInfo["value"][0]["OptionSet"]["Options"] select new Dynamics365OptionSetItem { Id = Convert.ToInt32(o["Value"]), Label = o["Label"]["LocalizedLabels"][0]["Label"].ToString() }).ToList() }; return(Ok(JObject.FromObject(optionSet))); } else { return(StatusCode((int)response.StatusCode, $"Failed to Retrieve records: {response.ReasonPhrase}")); } }
public ActionResult <string> ContractFile(string assignmentId) { if (string.IsNullOrEmpty(assignmentId)) { return(string.Empty); } string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' top='1'> <entity name='annotation' > <attribute name='filename' /> <attribute name='filesize' /> <attribute name='notetext' /> <filter> <condition attribute='filename' operator='ends-with' value='.pdf' /> <condition attribute='objecttypecodename' operator='eq' value='assignment' /> <condition attribute='notetext' operator='neq' value='Uploaded Document' /> <condition attribute='objectid' operator='eq' value= '{" + assignmentId + @"}' /> </filter> <order attribute='createdon' descending='true' /> <link-entity name='educ_assignment' from='educ_assignmentid' to='objectid'> <filter> <condition attribute='educ_contractstage' operator='eq' value='610410003' /> </filter> </link-entity> </entity> </fetch>"; var statement = $"annotations?fetchXml=" + WebUtility.UrlEncode(fetchXML); var response = new Dyn365WebAPI().SendRetrieveRequestAsync(statement, true); if (response.IsSuccessStatusCode) { return(Ok(response.Content.ReadAsStringAsync().Result)); } else { return(StatusCode((int)response.StatusCode, $"Failed to Retrieve records: {response.ReasonPhrase}")); } }