public static ApplicationLicenseSummary ToLicenseSummaryViewModel(this MicrosoftDynamicsCRMadoxioLicences licence, IList <MicrosoftDynamicsCRMadoxioApplication> applications) { ApplicationLicenseSummary licenseSummary = new ViewModels.ApplicationLicenseSummary() { LicenseId = licence.AdoxioLicencesid, LicenseNumber = licence.AdoxioLicencenumber, EstablishmentAddressStreet = licence.AdoxioEstablishmentaddressstreet, EstablishmentAddressCity = licence.AdoxioEstablishmentaddresscity, EstablishmentAddressPostalCode = licence.AdoxioEstablishmentaddresspostalcode, EstablishmentPhoneNumber = licence.AdoxioEstablishmentphone, EstablishmentEmail = licence.AdoxioEstablishment?.AdoxioEmail, EstablishmentId = licence.AdoxioEstablishment?.AdoxioEstablishmentid, ExpiryDate = licence.AdoxioExpirydate, Status = StatusUtility.GetLicenceStatus(licence, applications), AllowedActions = new List <ApplicationType>(), TransferRequested = (TransferRequested?)licence.AdoxioTransferrequested }; if (licence.AdoxioEstablishment != null) { licenseSummary.EstablishmentName = licence.AdoxioEstablishment.AdoxioName; licenseSummary.EstablishmentIsOpen = licence.AdoxioEstablishment.AdoxioIsopen; } var mainApplication = applications.Where(app => app.Statuscode == (int)Public.ViewModels.AdoxioApplicationStatusCodes.Approved).FirstOrDefault(); var crsApplication = applications.Where(app => app.AdoxioApplicationTypeId.AdoxioName == "Cannabis Retail Store").FirstOrDefault(); if (mainApplication != null) { licenseSummary.ApplicationId = mainApplication.AdoxioApplicationid; } if (crsApplication != null) { licenseSummary.StoreInspected = crsApplication.AdoxioAppchecklistinspectionresults == (int)InspectionStatus.Pass; } if (licence.AdoxioLicenceType != null) { licenseSummary.LicenceTypeName = licence.AdoxioLicenceType.AdoxioName; } if (licence != null && licence.AdoxioLicenceType != null && licence.AdoxioLicenceType.AdoxioLicencetypesApplicationtypes != null) { foreach (var item in licence.AdoxioLicenceType.AdoxioLicencetypesApplicationtypes) { // check to see if there is an existing action on this licence. licenseSummary.AllowedActions.Add(item.ToViewModel()); } } return(licenseSummary); }
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))); }
public static ApplicationLicenseSummary ToLicenseSummaryViewModel(this MicrosoftDynamicsCRMadoxioLicences licence, IList <MicrosoftDynamicsCRMadoxioApplication> applications, IDynamicsClient dynamicsClient) { ApplicationLicenseSummary licenseSummary = new ViewModels.ApplicationLicenseSummary() { LicenseId = licence.AdoxioLicencesid, LicenseNumber = licence.AdoxioLicencenumber, LicenseSubCategory = (LicenseSubCategory?)licence.AdoxioLicencesubcategory, // TG added for wine stores EstablishmentAddressStreet = licence.AdoxioEstablishmentaddressstreet, EstablishmentAddressCity = licence.AdoxioEstablishmentaddresscity, EstablishmentAddressPostalCode = licence.AdoxioEstablishmentaddresspostalcode, EstablishmentPhoneNumber = licence.AdoxioEstablishmentphone, EstablishmentEmail = licence.AdoxioEstablishment?.AdoxioEmail, EstablishmentId = licence.AdoxioEstablishment?.AdoxioEstablishmentid, ExpiryDate = licence.AdoxioExpirydate, Status = StatusUtility.GetLicenceStatus(licence, applications), AllowedActions = new List <ApplicationType>(), TransferRequested = licence.AdoxioTransferrequested.HasValue && (EnumYesNo?)licence.AdoxioTransferrequested == EnumYesNo.Yes, Dormant = licence.AdoxioDormant.HasValue && (EnumYesNo?)licence.AdoxioDormant == EnumYesNo.Yes, Suspended = licence.AdoxioSuspended.HasValue && (EnumYesNo?)licence.AdoxioSuspended == EnumYesNo.Yes, Operated = licence.AdoxioOperated.HasValue && (EnumYesNo?)licence.AdoxioOperated == EnumYesNo.Yes, ThirdPartyOperatorAccountId = licence._adoxioThirdpartyoperatoridValue, TPORequested = licence.AdoxioTporequested.HasValue && (EnumYesNo?)licence.AdoxioTporequested == EnumYesNo.Yes, // indicate whether a third party operator app has been requested RepresentativeFullName = licence.AdoxioRepresentativename, RepresentativeEmail = licence.AdoxioRepresentativeemail, RepresentativePhoneNumber = licence.AdoxioRepresentativephone, RepresentativeCanSubmitPermanentChangeApplications = licence.AdoxioCansubmitpermanentchangeapplications, RepresentativeCanSignTemporaryChangeApplications = licence.AdoxioCansigntemporarychangeapplications, RepresentativeCanObtainLicenceInformation = licence.AdoxioCanobtainlicenceinformation, RepresentativeCanSignGroceryStoreProofOfSale = licence.AdoxioCansigngrocerystoreproofofsales, RepresentativeCanAttendEducationSessions = licence.AdoxioCanattendeducationsessions, RepresentativeCanAttendComplianceMeetings = licence.AdoxioCanattendcompliancemeetings, RepresentativeCanRepresentAtHearings = licence.AdoxioCanrepresentathearings }; if (licence.AdoxioThirdPartyOperatorId != null) { licenseSummary.ThirdPartyOperatorAccountName = licence.AdoxioThirdPartyOperatorId.Name; } if (licence.AdoxioEstablishment != null) { licenseSummary.EstablishmentName = licence.AdoxioEstablishment.AdoxioName; licenseSummary.EstablishmentIsOpen = licence.AdoxioEstablishment.AdoxioIsopen; } var mainApplication = applications.Where(app => app.Statuscode == (int)Public.ViewModels.AdoxioApplicationStatusCodes.Approved).FirstOrDefault(); // 2-13-2020 adjust criteria so that we get the first approved CRS rather than simply the first CRS, to ensure that we get the correct record. var crsApplication = applications.Where(app => app.Statuscode == (int)Public.ViewModels.AdoxioApplicationStatusCodes.Approved && app.AdoxioApplicationTypeId.AdoxioName == "Cannabis Retail Store").FirstOrDefault(); if (mainApplication != null) { licenseSummary.ApplicationId = mainApplication.AdoxioApplicationid; if (mainApplication.AdoxioApplicationTypeId != null) { licenseSummary.ApplicationTypeName = mainApplication.AdoxioApplicationTypeId.AdoxioName; licenseSummary.ApplicationTypeCategory = (ApplicationTypeCategory?)mainApplication.AdoxioApplicationTypeId.AdoxioCategory; } } if (crsApplication != null) { // 2-7-2020 set the criteria to be No Contraventions rather than Pass. LCSD-2524 licenseSummary.StoreInspected = crsApplication.AdoxioAppchecklistinspectionresults == (int)InspectionStatus.NoContraventions; } if (licence.AdoxioLicenceType != null) { licenseSummary.LicenceTypeName = licence.AdoxioLicenceType.AdoxioName; licenseSummary.LicenceTypeCategory = (LicenceTypeCategory?)licence.AdoxioLicenceType.AdoxioCategory; } if (licence != null && licence.AdoxioLicenceType != null && licence.AdoxioLicenceType.AdoxioLicencetypesApplicationtypes != null) { foreach (var item in licence.AdoxioLicenceType.AdoxioLicencetypesApplicationtypes) { // check to see if there is an existing action on this licence. licenseSummary.AllowedActions.Add(item.ToViewModel()); } } licenseSummary.Endorsements = GetEndorsements(licenseSummary.LicenseId, dynamicsClient); return(licenseSummary); }