public static void CreateLicenceDocumentLocation(this IDynamicsClient _dynamicsClient, MicrosoftDynamicsCRMadoxioLicences licenceEntity, string folderName, string name) { // set the parent document library. var parentDocumentLibraryReference = _dynamicsClient.GetDocumentLocationReferenceByRelativeURL("adoxio_licences"); var licenceUri = _dynamicsClient.GetEntityURI("adoxio_licenceses", licenceEntity.AdoxioLicencesid); // now create a document location to link them. // Create the SharePointDocumentLocation entity var mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation { RegardingobjectIdEventODataBind = licenceUri, ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference), Relativeurl = folderName, Description = "Licence Files", Name = name }; var sharepointdocumentlocationid = _dynamicsClient.DocumentLocationExistsWithCleanup(mdcsdl); if (sharepointdocumentlocationid == null) { try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (HttpOperationException odee) { Log.Error(odee, "Error creating SharepointDocumentLocation"); mdcsdl = null; } if (mdcsdl != null) { var sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); var oDataId = new Odataid { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Licenceses.AddReference(licenceEntity.AdoxioLicencesid, "adoxio_licences_SharePointDocumentLocations", oDataId); } catch (HttpOperationException odee) { Log.Error(odee, "Error adding reference to SharepointDocumentLocation"); } } } }
private static void CreateContactDocumentLocation(this IDynamicsClient _dynamicsClient, MicrosoftDynamicsCRMcontact contact, string folderName, string name) { var parentDocumentLibraryReference = _dynamicsClient.GetDocumentLocationReferenceByRelativeURL("contact"); var contactUri = _dynamicsClient.GetEntityURI("contacts", contact.Contactid); // now create a document location to link them. // Create the SharePointDocumentLocation entity var mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation { RegardingobjectIdContactODataBind = contactUri, ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference), Relativeurl = folderName, Description = "Contact Files", Name = name }; var sharepointdocumentlocationid = _dynamicsClient.DocumentLocationExistsWithCleanup(mdcsdl); if (sharepointdocumentlocationid == null) { try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (HttpOperationException odee) { Log.Error(odee, "Error creating SharepointDocumentLocation"); mdcsdl = null; } if (mdcsdl != null) { var sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); var oDataId = new Odataid { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Contacts.AddReference(contact.Contactid, "adoxio_application_SharePointDocumentLocations", oDataId); } catch (HttpOperationException odee) { Log.Error(odee, "Error adding reference to SharepointDocumentLocation"); } } } }
public static void CreateApplicationDocumentLocation(this IDynamicsClient _dynamicsClient, MicrosoftDynamicsCRMadoxioApplication application, string folderName, string name) { // now create a document location to link them. var parentDocumentLibraryReference = _dynamicsClient.GetDocumentLocationReferenceByRelativeURL("adoxio_application"); var regardingobjectId = _dynamicsClient.GetEntityURI("adoxio_applications", application.AdoxioApplicationid); // Create the SharePointDocumentLocation entity var mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation { RegardingobjectidAdoxioApplicationODataBind = regardingobjectId, ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference), Relativeurl = folderName, Description = "Application Files", Name = name }; var sharepointdocumentlocationid = _dynamicsClient.DocumentLocationExistsWithCleanup(mdcsdl); if (sharepointdocumentlocationid == null) { sharepointdocumentlocationid = _dynamicsClient.CreateDocumentLocation(mdcsdl); var sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", sharepointdocumentlocationid); var oDataId = new Odataid { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Applications.AddReference(application.AdoxioApplicationid, "adoxio_application_SharePointDocumentLocations", oDataId); } catch (HttpOperationException odee) { Log.Error(odee, "Error adding reference to SharepointDocumentLocation"); } } }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='accountId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this IAccounts operations, string accountId, string fieldname, Odataid odataid = default) { operations.AddReferenceAsync(accountId, fieldname, odataid).GetAwaiter().GetResult(); }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='contactId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this IContacts operations, string contactId, string fieldname, Odataid odataid = default(Odataid)) { operations.AddReferenceAsync(contactId, fieldname, odataid).GetAwaiter().GetResult(); }
/// <summary> /// Add reference to adoxio_licenceses /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='licenceId'> /// key: adoxio_licenceid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this ILicenceses operations, string licenceId, string fieldname, Odataid odataid = default) { operations.AddReferenceAsync(licenceId, fieldname, odataid).GetAwaiter().GetResult(); }
private async Task CreateFederalReportDocumentLocation(MicrosoftDynamicsCRMadoxioFederalreportexport federalReport, string folderName, string name) { // now create a document location to link them. // Create the SharePointDocumentLocation entity MicrosoftDynamicsCRMsharepointdocumentlocation mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation() { Relativeurl = folderName, Description = "Federal Report Files", Name = name }; try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (HttpOperationException odee) { _logger.LogError(odee, "Error creating SharepointDocumentLocation"); mdcsdl = null; } if (mdcsdl != null) { // set the parent document library. string parentDocumentLibraryReference = GetDocumentLocationReferenceByRelativeURL("adoxio_federalreportexport", name); string exportUri = _dynamicsClient.GetEntityURI("adoxio_federalreportexports", federalReport.AdoxioFederalreportexportid); // add a regardingobjectid. var patchSharePointDocumentLocationIncident = new MicrosoftDynamicsCRMsharepointdocumentlocation() { RegardingobjectIdFederalReportExportODataBind = exportUri, ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference), Relativeurl = name, Description = "Federal Report Files", }; try { _dynamicsClient.Sharepointdocumentlocations.Update(mdcsdl.Sharepointdocumentlocationid, patchSharePointDocumentLocationIncident); } catch (HttpOperationException odee) { _logger.LogError(odee, "Error adding reference SharepointDocumentLocation to federal report"); } string sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); Odataid oDataId = new Odataid() { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Federalreportexports.AddReference(federalReport.AdoxioFederalreportexportid, "adoxio_federalreportexport_SharePointDocumentLocations", oDataId); } catch (HttpOperationException odee) { _logger.LogError(odee, "Error adding reference to SharepointDocumentLocation"); } } }
/// <summary> /// Change reference to adoxio_applications /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioApplicationid'> /// key: adoxio_applicationid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void ChangeReference(this IApplications operations, string adoxioApplicationid, string fieldname, Odataid odataid = default(Odataid)) { operations.ChangeReferenceAsync(adoxioApplicationid, fieldname, odataid).GetAwaiter().GetResult(); }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='workerId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task AddReferenceAsync(this IWorkers operations, string workerId, string fieldname, Odataid odataid = default(Odataid), CancellationToken cancellationToken = default(CancellationToken)) { (await operations.AddReferenceWithHttpMessagesAsync(workerId, fieldname, odataid, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='workerId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this IWorkers operations, string workerId, string fieldname, Odataid odataid = default(Odataid)) { operations.AddReferenceAsync(workerId, fieldname, odataid).GetAwaiter().GetResult(); }
private async Task initializeSharepoint(MicrosoftDynamicsCRMadoxioApplication adoxioApplication) { // create a SharePointDocumentLocation link string folderName = GetApplicationFolderName(adoxioApplication); string name = adoxioApplication.AdoxioJobnumber + " Files"; // Create the folder bool folderExists = await _sharePointFileManager.FolderExists(ApplicationDocumentUrlTitle, folderName); if (!folderExists) { try { await _sharePointFileManager.CreateFolder(ApplicationDocumentUrlTitle, folderName); } catch (SharePointRestException spre) { _logger.LogError("Error creating Sharepoint Folder"); _logger.LogError($"List is: {ApplicationDocumentUrlTitle}"); _logger.LogError($"FolderName is: {folderName}"); _logger.LogError($"Request is: {spre.Request.Content}"); _logger.LogError($"Response is: {spre.Response.Content}"); _logger.LogError($"Error is: {spre.Message} {spre.StackTrace}"); throw spre; } catch (Exception e) { _logger.LogError("Error creating Sharepoint Folder"); _logger.LogError($"List is: {ApplicationDocumentUrlTitle}"); _logger.LogError($"FolderName is: {folderName}"); _logger.LogError($"Error is: {e.Message} {e.StackTrace}"); throw e; } } // Create the SharePointDocumentLocation entity MicrosoftDynamicsCRMsharepointdocumentlocation mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation() { Relativeurl = folderName, Description = "Application Files", Name = name }; try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (OdataerrorException odee) { string mdcsdlId = _dynamicsClient.GetCreatedRecord(odee, null); if (!string.IsNullOrEmpty(mdcsdlId)) { mdcsdl.Sharepointdocumentlocationid = mdcsdlId; } else { _logger.LogError("Error creating SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); mdcsdl = null; } } if (mdcsdl != null) { // add a regardingobjectid. string applicationReference = _dynamicsClient.GetEntityURI("adoxio_applications", adoxioApplication.AdoxioApplicationid); var patchSharePointDocumentLocation = new MicrosoftDynamicsCRMsharepointdocumentlocation(); patchSharePointDocumentLocation.RegardingobjectidAdoxioApplicationODataBind = applicationReference; // set the parent document library. string parentDocumentLibraryReference = GetDocumentLocationReferenceByRelativeURL("adoxio_application"); patchSharePointDocumentLocation.ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference); try { _dynamicsClient.Sharepointdocumentlocations.Update(mdcsdl.Sharepointdocumentlocationid, patchSharePointDocumentLocation); } catch (OdataerrorException odee) { _logger.LogError("Error adding reference SharepointDocumentLocation to application"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); } string sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); // update the sharePointLocationData. Odataid oDataId = new Odataid() { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Applications.AddReference(adoxioApplication.AdoxioApplicationid, "adoxio_application_SharePointDocumentLocations", oDataId); } catch (OdataerrorException odee) { _logger.LogError("Error adding reference to SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); } } }
/// <summary> /// Add reference to adoxio_federalreportexport /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='federalReportExportId'> /// key: adoxio_federalreportexportid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this IFederalreportexports operations, string federalReportExportId, string fieldname, Odataid odataid = default) { operations.AddReferenceAsync(federalReportExportId, fieldname, odataid).GetAwaiter().GetResult(); }
private async Task CreateSharepointDynamicsLink(MicrosoftDynamicsCRMadoxioWorker worker) { // create a SharePointDocumentLocation link string folderName = worker.GetDocumentFolderName(); string name = worker.AdoxioWorkerid + " Files"; _fileManagerClient.CreateFolderIfNotExist(_logger, WorkerDocumentUrlTitle, folderName); // Create the SharePointDocumentLocation entity MicrosoftDynamicsCRMsharepointdocumentlocation mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation() { Relativeurl = folderName, Description = "Worker Qualification", Name = name }; try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error creating SharepointDocumentLocation"); mdcsdl = null; } if (mdcsdl != null) { // add a regardingobjectid. string workerReference = _dynamicsClient.GetEntityURI("adoxio_workers", worker.AdoxioWorkerid); var patchSharePointDocumentLocation = new MicrosoftDynamicsCRMsharepointdocumentlocation(); patchSharePointDocumentLocation.RegardingobjectidWorkerApplicationODataBind = workerReference; // set the parent document library. string parentDocumentLibraryReference = GetDocumentLocationReferenceByRelativeURL(WorkerDocumentUrlTitle); patchSharePointDocumentLocation.ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference); try { _dynamicsClient.Sharepointdocumentlocations.Update(mdcsdl.Sharepointdocumentlocationid, patchSharePointDocumentLocation); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error adding reference SharepointDocumentLocation to application"); throw httpOperationException; } string sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); // update the sharePointLocationData. Odataid oDataId = new Odataid() { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Workers.AddReference(worker.AdoxioWorkerid, "adoxio_worker_SharePointDocumentLocations", oDataId); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error adding reference to SharepointDocumentLocation"); throw httpOperationException; } } }
/// <summary> /// Add reference to adoxio_specialevents /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='specialEventId'> /// key: adoxio_specialeventid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> public static void AddReference(this ISpecialevents operations, string specialEventId, string fieldname, Odataid odataid = default) { operations.AddReferenceAsync(specialEventId, fieldname, odataid).GetAwaiter().GetResult(); }
public async Task <IActionResult> CreateApplication([FromBody] ViewModels.AdoxioApplication item) { // for association with current user string userJson = _httpContextAccessor.HttpContext.Session.GetString("UserSettings"); UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(userJson); int count = GetSubmittedCountByApplicant(userSettings.AccountId); if (count >= 8) { return(BadRequest("8 applications have already been submitted. Can not create more")); } MicrosoftDynamicsCRMadoxioApplication adoxioApplication = new MicrosoftDynamicsCRMadoxioApplication(); // copy received values to Dynamics Application adoxioApplication.CopyValues(item); adoxioApplication.AdoxioApplicanttype = (int?)item.applicantType; try { var adoxioLicencetype = _dynamicsClient.GetAdoxioLicencetypeByName(item.licenseType); // set license type relationship adoxioApplication.AdoxioLicenceTypeODataBind = _dynamicsClient.GetEntityURI("adoxio_licencetypes", adoxioLicencetype.AdoxioLicencetypeid); adoxioApplication.AdoxioApplicantODataBind = _dynamicsClient.GetEntityURI("accounts", userSettings.AccountId); adoxioApplication = _dynamicsClient.Applications.Create(adoxioApplication); } catch (OdataerrorException odee) { string applicationId = _dynamicsClient.GetCreatedRecord(odee, null); if (!string.IsNullOrEmpty(applicationId) && Guid.TryParse(applicationId, out Guid applicationGuid)) { adoxioApplication = await _dynamicsClient.GetApplicationById(applicationGuid); } else { _logger.LogError("Error creating application"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); // fail if we can't create. throw (odee); } } // in case the job number is not there, try getting the record from the server. if (adoxioApplication.AdoxioJobnumber == null) { _logger.LogError("AdoxioJobnumber is null, fetching record again."); Guid id = Guid.Parse(adoxioApplication.AdoxioApplicationid); adoxioApplication = await _dynamicsClient.GetApplicationById(id); } if (adoxioApplication.AdoxioJobnumber == null) { _logger.LogError("Unable to get the Job Number for the Application."); throw new Exception("Error creating Licence Application."); } // create a SharePointDocumentLocation link string folderName = GetApplicationFolderName(adoxioApplication); string name = adoxioApplication.AdoxioJobnumber + " Files"; // Create the folder bool folderExists = await _sharePointFileManager.FolderExists(ApplicationDocumentUrlTitle, folderName); if (!folderExists) { try { var folder = await _sharePointFileManager.CreateFolder(ApplicationDocumentUrlTitle, folderName); } catch (Exception e) { _logger.LogError("Error creating Sharepoint Folder"); _logger.LogError($"List is: {ApplicationDocumentUrlTitle}"); _logger.LogError($"FolderName is: {folderName}"); throw e; } } // Create the SharePointDocumentLocation entity MicrosoftDynamicsCRMsharepointdocumentlocation mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation() { Relativeurl = folderName, Description = "Application Files", Name = name }; try { mdcsdl = _dynamicsClient.SharepointDocumentLocations.Create(mdcsdl); } catch (OdataerrorException odee) { string mdcsdlId = _dynamicsClient.GetCreatedRecord(odee, null); if (!string.IsNullOrEmpty(mdcsdlId)) { mdcsdl.Sharepointdocumentlocationid = mdcsdlId; } else { _logger.LogError("Error creating SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); mdcsdl = null; } } if (mdcsdl != null) { // add a regardingobjectid. string applicationReference = _dynamicsClient.GetEntityURI("adoxio_applications", adoxioApplication.AdoxioApplicationid); var patchSharePointDocumentLocation = new MicrosoftDynamicsCRMsharepointdocumentlocation(); patchSharePointDocumentLocation.RegardingobjectidAdoxioApplicationODataBind = applicationReference; // set the parent document library. string parentDocumentLibraryReference = GetDocumentLocationReferenceByRelativeURL("adoxio_application"); patchSharePointDocumentLocation.ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference); try { _dynamicsClient.SharepointDocumentLocations.Update(mdcsdl.Sharepointdocumentlocationid, patchSharePointDocumentLocation); } catch (OdataerrorException odee) { _logger.LogError("Error adding reference SharepointDocumentLocation to application"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); } string sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); // update the sharePointLocationData. Odataid oDataId = new Odataid() { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Applications.AddReference(adoxioApplication.AdoxioApplicationid, "adoxio_application_SharePointDocumentLocations", oDataId); } catch (OdataerrorException odee) { _logger.LogError("Error adding reference to SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); } } return(Json(await adoxioApplication.ToViewModel(_dynamicsClient))); }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='accountId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task AddReferenceAsync(this IAccounts operations, string accountId, string fieldname, Odataid odataid = default, CancellationToken cancellationToken = default) { (await operations.AddReferenceWithHttpMessagesAsync(accountId, fieldname, odataid, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Add reference to adoxio_workers /// </summary> /// <param name='accountId'> /// key: adoxio_workerid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="HttpOperationException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse> AddReferenceWithHttpMessagesAsync(string accountId, string fieldname, Odataid odataid = default, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default) { if (accountId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "workerId"); } if (fieldname == null) { throw new ValidationException(ValidationRules.CannotBeNull, "fieldname"); } if (odataid != null) { odataid.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("accountid", accountId); tracingParameters.Add("fieldname", fieldname); tracingParameters.Add("odataid", odataid); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "AddReference", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "accounts({accountid})/{fieldname}/$ref").ToString(); _url = _url.Replace("{accountid}", System.Uri.EscapeDataString(accountId)); _url = _url.Replace("{fieldname}", System.Uri.EscapeDataString(fieldname)); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (odataid != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(odataid, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 204) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); Odataerror _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Odataerror>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
private async Task CreateSharepointDynamicsLink(MicrosoftDynamicsCRMadoxioWorker worker) { // create a SharePointDocumentLocation link string folderName = await FileController.GetFolderName("worker", worker.AdoxioWorkerid, _dynamicsClient); string name = worker.AdoxioWorkerid + " Files"; SharePointFileManager _sharePointFileManager = new SharePointFileManager(_configuration); // Create the folder bool folderExists = await _sharePointFileManager.FolderExists(SharePointFileManager.WorkertDocumentUrlTitle, folderName); if (!folderExists) { try { await _sharePointFileManager.CreateFolder(SharePointFileManager.WorkertDocumentUrlTitle, folderName); } catch (Exception e) { _logger.LogError("Error creating Sharepoint Folder"); _logger.LogError($"List is: {SharePointFileManager.WorkertDocumentUrlTitle}"); _logger.LogError($"FolderName is: {folderName}"); throw e; } } // Create the SharePointDocumentLocation entity MicrosoftDynamicsCRMsharepointdocumentlocation mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation() { Relativeurl = folderName, Description = "Worker Qualification", Name = name }; try { mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl); } catch (HttpOperationException httpOperationException) { _logger.LogError("Error creating SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(httpOperationException.Request.Content); _logger.LogError("Response:"); _logger.LogError(httpOperationException.Response.Content); mdcsdl = null; } if (mdcsdl != null) { // add a regardingobjectid. string workerReference = _dynamicsClient.GetEntityURI("adoxio_workers", worker.AdoxioWorkerid); var patchSharePointDocumentLocation = new MicrosoftDynamicsCRMsharepointdocumentlocation(); patchSharePointDocumentLocation.RegardingobjectidWorkerApplicationODataBind = workerReference; // set the parent document library. string parentDocumentLibraryReference = GetDocumentLocationReferenceByRelativeURL(SharePointFileManager.WorkertDocumentUrlTitle); patchSharePointDocumentLocation.ParentsiteorlocationSharepointdocumentlocationODataBind = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference); try { _dynamicsClient.Sharepointdocumentlocations.Update(mdcsdl.Sharepointdocumentlocationid, patchSharePointDocumentLocation); } catch (HttpOperationException httpOperationException) { _logger.LogError("Error adding reference SharepointDocumentLocation to application"); _logger.LogError("Request:"); _logger.LogError(httpOperationException.Request.Content); _logger.LogError("Response:"); _logger.LogError(httpOperationException.Response.Content); throw httpOperationException; } string sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations", mdcsdl.Sharepointdocumentlocationid); // update the sharePointLocationData. Odataid oDataId = new Odataid() { OdataidProperty = sharePointLocationData }; try { _dynamicsClient.Workers.AddReference(worker.AdoxioWorkerid, "adoxio_worker_SharePointDocumentLocations", oDataId); } catch (HttpOperationException httpOperationException) { _logger.LogError("Error adding reference to SharepointDocumentLocation"); _logger.LogError("Request:"); _logger.LogError(httpOperationException.Request.Content); _logger.LogError("Response:"); _logger.LogError(httpOperationException.Response.Content); throw httpOperationException; } } }
/// <summary> /// Change reference to adoxio_applications /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioApplicationid'> /// key: adoxio_applicationid /// </param> /// <param name='fieldname'> /// key: fieldname /// </param> /// <param name='odataid'> /// reference value /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task ChangeReferenceAsync(this IApplications operations, string adoxioApplicationid, string fieldname, Odataid odataid = default(Odataid), CancellationToken cancellationToken = default(CancellationToken)) { (await operations.ChangeReferenceWithHttpMessagesAsync(adoxioApplicationid, fieldname, odataid, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
public ActionResult CreateOrUpdate([FromBody] Sol sol) { if (sol == null || string.IsNullOrEmpty(sol.SolLicenceNumber) || !sol.SolLicenceNumber.Contains("-")) { return(BadRequest()); } // format of the "SolLicenceNumber" field is {EventLicenceNumber}-{LocationReference} string solIdEscaped = sol.SolLicenceNumber.Replace("'", "''"); if (solIdEscaped.Contains("-")) { solIdEscaped = solIdEscaped.Substring(0, solIdEscaped.IndexOf("-")); } // string locationReference = sol.SolLicenceNumber.Substring(sepLicenceNumber.Length); // determine if the record is new. MicrosoftDynamicsCRMadoxioSpecialevent existingRecord = _dynamicsClient.GetSpecialEventByLicenceNumber(solIdEscaped); if (existingRecord == null) // new record { MicrosoftDynamicsCRMadoxioSpecialevent newRecord = new MicrosoftDynamicsCRMadoxioSpecialevent() { AdoxioCapacity = sol.Capacity, AdoxioSpecialeventdescripton = sol.EventDescription, AdoxioEventname = AdjustString255(sol.EventName), AdoxioSpecialeventpermitnumber = solIdEscaped, // applicant AdoxioSpecialeventapplicant = AdjustString255(sol.Applicant?.ApplicantName), AdoxioSpecialeventapplicantemail = AdjustString255(sol.Applicant?.EmailAddress), AdoxioSpecialeventapplicantphone = sol.Applicant?.PhoneNumber, // location AdoxioSpecialeventstreet1 = AdjustString255(sol.Applicant?.Address?.Address1), AdoxioSpecialeventstreet2 = AdjustString255(sol.Applicant?.Address?.Address2), AdoxioSpecialeventcity = AdjustString255(sol.Applicant?.Address?.City), AdoxioSpecialeventpostalcode = sol.Applicant?.Address?.PostalCode, AdoxioSpecialeventprovince = AdjustString255(sol.Applicant?.Address?.Province), // responsible individual AdoxioResponsibleindividualfirstname = AdjustString255(sol.ResponsibleIndividual?.FirstName), AdoxioResponsibleindividuallastname = AdjustString255(sol.ResponsibleIndividual?.LastName), AdoxioResponsibleindividualmiddleinitial = AdjustString255(sol.ResponsibleIndividual?.MiddleInitial), AdoxioResponsibleindividualposition = AdjustString255(sol.ResponsibleIndividual?.Position), AdoxioResponsibleindividualsir = sol.ResponsibleIndividual?.SirNumber, // tasting event AdoxioTastingevent = sol.TastingEvent }; newRecord.AdoxioSpecialeventSpecialeventlocations = new List <MicrosoftDynamicsCRMadoxioSpecialeventlocation>(); newRecord.AdoxioSpecialeventSpecialeventlocations.Add(ExtractLocation(sol)); // notes if (sol.SolNote != null) { newRecord.AdoxioSpecialeventSpecialeventnotes = new List <MicrosoftDynamicsCRMadoxioSpecialeventnote>(); foreach (var item in sol.SolNote) { newRecord.AdoxioSpecialeventSpecialeventnotes.Add( new MicrosoftDynamicsCRMadoxioSpecialeventnote() { AdoxioNote = item.Text, AdoxioAuthor = AdjustString255(item.Author), Createdon = AdjustDateTime(item.CreatedDate), Modifiedon = AdjustDateTime(item.LastUpdatedDate) }); } } // terms and conditions if (sol.TsAndCs != null) { newRecord.AdoxioSpecialeventSpecialeventtsacs = new List <MicrosoftDynamicsCRMadoxioSpecialeventtandc>(); foreach (var item in sol.TsAndCs) { var newTandC = new MicrosoftDynamicsCRMadoxioSpecialeventtandc() { AdoxioTermsandcondition = item.Text, AdoxioOriginator = AdjustString255(item.Originator) }; if (item.TandcType == TandcType.GlobalCondition) { newTandC.AdoxioTermsandconditiontype = true; } newRecord.AdoxioSpecialeventSpecialeventtsacs.Add(newTandC); } } try { newRecord = _dynamicsClient.Specialevents.Create(newRecord); _logger.Information($"Created special event {newRecord.AdoxioSpecialeventid}"); } catch (HttpOperationException httpOperationException) { _logger.Error(httpOperationException, "Error creating special event record"); // fail return(StatusCode(500, "Server Error creating record.")); } } else // existing record. { if (sol.Location != null) { MicrosoftDynamicsCRMadoxioSpecialeventlocation location = ExtractLocation(sol); try { location = _dynamicsClient.Specialeventlocations.Create(location); _logger.Information( $"Created new special event location {location.AdoxioSpecialeventlocationid}"); } catch (HttpOperationException httpOperationException) { _logger.Error(httpOperationException, "Error creating special event schedule"); // fail return(StatusCode(500, "Server Error creating record.")); } // now bind the record to the parent. var specialEventLocationData = _dynamicsClient.GetEntityURI("adoxio_specialeventlocations", location.AdoxioSpecialeventlocationid); var oDataIdEventLocation = new Odataid { OdataidProperty = specialEventLocationData }; try { _dynamicsClient.Specialevents.AddReference(existingRecord.AdoxioSpecialeventid, "adoxio_specialevent_specialeventlocations", oDataIdEventLocation); } catch (HttpOperationException odee) { Log.Error(odee, "Error adding reference to adoxio_specialevent_specialeventlocations"); } } } return(Ok()); }