public async Task <ActionResult> GetApplicationType([FromRoute] string id) { var applicationType = await _dynamicsClient.GetApplicationTypeById(id); if (applicationType == null) { return(new NotFoundResult()); } return(new JsonResult(applicationType.ToViewModel())); }
public ActionResult CancelTransfer(LicenceTransfer item) { if (!ModelState.IsValid) { return(BadRequest()); } // check access to licence MicrosoftDynamicsCRMadoxioLicences adoxioLicense = _dynamicsClient.GetLicenceByIdWithChildren(item.LicenceId); if (adoxioLicense == null) { return(NotFound()); } if (!CurrentUserHasAccessToLicenseOwnedBy(adoxioLicense.AdoxioLicencee.Accountid)) { return(Forbid()); } try { var no = 845280000; var patchLicence = new MicrosoftDynamicsCRMadoxioLicences() { AdoxioTransferrequested = no }; // create application _dynamicsClient.Licenceses.Update(item.LicenceId, patchLicence); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error cancelling licence transfer"); // fail if we can't create. throw; } // Delete the Proposed Owner (ProposedOwnerODataBind) try { _dynamicsClient.Licenceses.DeleteReferenceWithHttpMessagesAsync(item.LicenceId, "adoxio_ProposedOwner").GetAwaiter().GetResult(); } catch (HttpOperationException httpOperationException) { if (httpOperationException.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { _logger.LogError(httpOperationException, "Error deleting proposed owner"); throw; } } // find the related application and delete it. foreach (var application in adoxioLicense.AdoxioAdoxioLicencesAdoxioApplicationAssignedLicence) { // get the full application type.] var applicationType = _dynamicsClient.GetApplicationTypeById(application._adoxioApplicationtypeidValue).GetAwaiter().GetResult(); if (applicationType.AdoxioName.Contains("CRS Transfer of Ownership")) { var patchApplication = new MicrosoftDynamicsCRMadoxioApplication() { //Statecode = (int?)AdoxioApplicationStatusCodes.Cancelled, Statuscode = (int?)AdoxioApplicationStatusCodes.Terminated }; try { _dynamicsClient.Applications.Update(application.AdoxioApplicationid, patchApplication); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error cancelling related application"); // fail if we can't create. throw; } } } return(Ok()); }