public async Task <IActionResult> UpdateLicenceEstablishment([FromBody] ViewModels.ApplicationLicenseSummary item, string licenceId) { if (item == null || string.IsNullOrEmpty(licenceId) || licenceId != item.LicenseId) { return(BadRequest()); } MicrosoftDynamicsCRMadoxioLicences licence = _dynamicsClient.GetLicenceByIdWithChildren(licenceId); if (licence == null) { return(NotFound()); } if (!CurrentUserHasAccessToLicenseOwnedBy(licence.AdoxioLicencee.Accountid)) { return(Forbid()); } MicrosoftDynamicsCRMadoxioLicences patchObject = new MicrosoftDynamicsCRMadoxioLicences() { AdoxioEstablishmentphone = item.EstablishmentPhoneNumber, AdoxioEstablishmentaddresscity = item.EstablishmentAddressCity, AdoxioEstablishmentaddressstreet = item.EstablishmentAddressStreet, AdoxioEstablishmentaddresspostalcode = item.EstablishmentAddressPostalCode }; try { await _dynamicsClient.Licenceses.UpdateAsync(licenceId, patchObject); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error updating licence establishment"); throw new Exception("Unable to update licence establishment"); } try { licence = _dynamicsClient.GetLicenceByIdWithChildren(licenceId); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error getting licence"); throw new Exception("Unable to get licence after update"); } IEnumerable <MicrosoftDynamicsCRMadoxioApplication> applicationsInProgress = _dynamicsClient.GetApplicationsForLicenceByApplicant(licence.AdoxioLicencee.Accountid); var applications = applicationsInProgress.Where(app => app._adoxioAssignedlicenceValue == licence.AdoxioLicencesid).ToList(); licence.AdoxioLicenceType = ApplicationExtensions.GetCachedLicenceType(licence._adoxioLicencetypeValue, _dynamicsClient, _cache); return(new JsonResult(licence.ToLicenseSummaryViewModel(applications))); }
private List <ApplicationLicenseSummary> GetLicensesByLicencee(string licenceeId) { var expand = new List <string> { "adoxio_adoxio_licences_adoxio_application_AssignedLicence", "adoxio_LicenceType", "adoxio_establishment" }; List <ApplicationLicenseSummary> licenseSummaryList = new List <ApplicationLicenseSummary>(); IEnumerable <MicrosoftDynamicsCRMadoxioLicences> licences = null; if (string.IsNullOrEmpty(licenceeId)) { licences = _dynamicsClient.Licenceses.Get(expand: expand).Value; } else { var filter = $"_adoxio_licencee_value eq {licenceeId}"; try { licences = _dynamicsClient.Licenceses.Get(filter: filter, expand: expand, orderby: new List <string> { "modifiedon desc" }).Value; licences = licences .Where(licence => { return(licence.Statuscode != (int)LicenceStatusCodes.Cancelled && licence.Statuscode != (int)LicenceStatusCodes.Inactive); }) .Select(licence => { licence.AdoxioLicenceType = ApplicationExtensions.GetCachedLicenceType(licence._adoxioLicencetypeValue, _dynamicsClient, _cache); return(licence); }); } catch (HttpOperationException) { licences = null; } } if (licences != null) { IEnumerable <MicrosoftDynamicsCRMadoxioApplication> applicationsInProgress = _dynamicsClient.GetApplicationsForLicenceByApplicant(licenceeId); foreach (var licence in licences) { var applications = applicationsInProgress.Where(app => app._adoxioAssignedlicenceValue == licence.AdoxioLicencesid).ToList(); licenseSummaryList.Add(licence.ToLicenseSummaryViewModel(applications)); } } return(licenseSummaryList); }