Beispiel #1
0
        /// <summary>
        /// Gets the number of applications that are submitted
        /// </summary>
        /// <param name="applicantId"></param>
        /// <returns></returns>
        private int GetSubmittedCountByApplicant(string applicantId)
        {
            var result = 0;

            if (!string.IsNullOrEmpty(applicantId))
            {
                var filter = $"_adoxio_applicant_value eq {applicantId} and adoxio_paymentrecieved eq true and statuscode ne {(int)AdoxioApplicationStatusCodes.Terminated}";
                filter += $" and statuscode ne {(int)AdoxioApplicationStatusCodes.Denied}";
                filter += $" and statuscode ne {(int)AdoxioApplicationStatusCodes.Cancelled}";
                filter += $" and statuscode ne {(int)AdoxioApplicationStatusCodes.TerminatedAndRefunded}";

                var adoxioLicencetype = _dynamicsClient.GetAdoxioLicencetypeByName("Cannabis Retail Store");
                if (adoxioLicencetype != null)
                {
                    filter += $" and _adoxio_licencetype_value eq {adoxioLicencetype.AdoxioLicencetypeid} ";
                }

                try
                {
                    result = _dynamicsClient.Applications.Get(filter: filter).Value.Count;
                }
                catch (OdataerrorException)
                {
                    result = 0;
                }
            }
            return(result);
        }
        private string GetLicenceTypeId(string name)
        {
            string sanitized = name.Replace(" ", "_");
            string cacheKey  = $"LTI_CODE_{sanitized}";
            string result;

            if (!_cache.TryGetValue(cacheKey, out result))
            {
                try
                {
                    result = _dynamicsClient.GetAdoxioLicencetypeByName(name)?.AdoxioLicencetypeid;
                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            // Set the cache to expire in an hour.
                                            .SetAbsoluteExpiration(TimeSpan.FromDays(7));

                    // Save data in cache.
                    _cache.Set(cacheKey, result, cacheEntryOptions);
                }
                catch (Exception)
                {
                    result = null;
                }
            }

            return(result);
        }
Beispiel #3
0
        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);
            MicrosoftDynamicsCRMadoxioApplication adoxioApplication = new MicrosoftDynamicsCRMadoxioApplication();

            // copy received values to Dynamics Application
            adoxioApplication.CopyValues(item);
            adoxioApplication.AdoxioApplicanttype = (int?)item.applicantType;
            try
            {
                adoxioApplication = _dynamicsClient.Applications.Create(adoxioApplication);
            }
            catch (OdataerrorException odee)
            {
                _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);
            }

            MicrosoftDynamicsCRMadoxioApplication patchAdoxioApplication = new MicrosoftDynamicsCRMadoxioApplication();

            // set license type relationship

            var adoxioLicencetype = _dynamicsClient.GetAdoxioLicencetypeByName(item.licenseType).Result;

            patchAdoxioApplication.AdoxioLicenceTypeODataBind = _dynamicsClient.GetEntityURI("adoxio_licencetypes", adoxioLicencetype.AdoxioLicencetypeid);;
            patchAdoxioApplication.AdoxioApplicantODataBind   = _dynamicsClient.GetEntityURI("adoxio_applications", userSettings.AccountId);
            try
            {
                _dynamicsClient.Applications.Update(adoxioApplication.AdoxioApplicationid, patchAdoxioApplication);
            }
            catch (OdataerrorException odee)
            {
                _logger.LogError("Error updating 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);
            }
            return(Json(await adoxioApplication.ToViewModel(_dynamicsClient)));
        }
Beispiel #4
0
        public async Task <JsonResult> CreateApplicationForAction(string licenceId, string applicationTypeName)
        {
            // for association with current user
            string       userJson     = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(userJson);

            var expand = new List <string> {
                "adoxio_Licencee",
                "adoxio_LicenceType",
                "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence",
                "adoxio_adoxio_licences_adoxio_application_AssignedLicence",
                "adoxio_establishment"
            };

            MicrosoftDynamicsCRMadoxioLicences adoxioLicense = _dynamicsClient.Licenceses.GetByKey(licenceId, expand: expand);

            if (adoxioLicense == null)
            {
                throw new Exception("Error getting license.");
            }
            else
            {
                var adoxioLicencetype = _dynamicsClient.GetAdoxioLicencetypeByName(applicationTypeName);

                MicrosoftDynamicsCRMadoxioApplication application = new MicrosoftDynamicsCRMadoxioApplication()
                {
                    // START WITH BLANK FIELDS.
                };

                application.CopyValuesForChangeOfLocation(adoxioLicense, applicationTypeName != "CRS Location Change");

                // get the previous application for the licence.

                application.AdoxioApplicanttype = adoxioLicense.AdoxioLicencee.AdoxioBusinesstype;

                // set applicaiton type relationship
                var applicationType = _dynamicsClient.GetApplicationTypeByName(applicationTypeName);
                application.AdoxioApplicationTypeIdODataBind = _dynamicsClient.GetEntityURI("adoxio_applicationtypes", applicationType.AdoxioApplicationtypeid);

                // set license type relationship
                application.AdoxioLicenceTypeODataBind = _dynamicsClient.GetEntityURI("adoxio_licencetypes", adoxioLicense.AdoxioLicenceType.AdoxioLicencetypeid);
                application.AdoxioApplicantODataBind   = _dynamicsClient.GetEntityURI("accounts", userSettings.AccountId);

                application.AdoxioLicenceEstablishmentODataBind = _dynamicsClient.GetEntityURI("adoxio_establishments", adoxioLicense.AdoxioEstablishment.AdoxioEstablishmentid);

                try
                {
                    application = _dynamicsClient.Applications.Create(application);
                }
                catch (HttpOperationException httpOperationException)
                {
                    string applicationId = _dynamicsClient.GetCreatedRecord(httpOperationException, null);
                    if (!string.IsNullOrEmpty(applicationId) && Guid.TryParse(applicationId, out Guid applicationGuid))
                    {
                        application = await _dynamicsClient.GetApplicationById(applicationGuid);
                    }
                    else
                    {
                        _logger.LogError(httpOperationException, "Error creating application");
                        // fail if we can't create.
                        throw (httpOperationException);
                    }
                }

                // now bind the new application to the given licence.

                var patchApplication = new MicrosoftDynamicsCRMadoxioApplication()
                {
                    AdoxioAssignedLicenceODataBind = _dynamicsClient.GetEntityURI("adoxio_licenceses", licenceId)
                };

                try
                {
                    _dynamicsClient.Applications.Update(application.AdoxioApplicationid, patchApplication);
                }
                catch (HttpOperationException httpOperationException)
                {
                    _logger.LogError(httpOperationException, "Error updating application");
                }

                return(new JsonResult(await application.ToViewModel(_dynamicsClient)));
            }
        }
Beispiel #5
0
        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)));
        }
        public async Task GeocodeEstablishments(PerformContext hangfireContext, bool redoGeocoded)
        {
            if (hangfireContext != null)
            {
                _logger.LogInformation("Starting GeocodeEstablishments job.");
                hangfireContext.WriteLine("Starting GeocodeEstablishments job.");
            }


            // get licenses
            IList <MicrosoftDynamicsCRMadoxioLicences> licences = null;



            string crsTypeId  = _dynamics.GetAdoxioLicencetypeByName("Cannabis Retail Store")?.AdoxioLicencetypeid;
            string s119TypeId = _dynamics.GetAdoxioLicencetypeByName("Section 119 Authorization")?.AdoxioLicencetypeid;


            string licenseFilter = $"statuscode eq 1 and _adoxio_licencetype_value eq {crsTypeId}"; // only active licenses

            if (s119TypeId != null)
            {
                licenseFilter += $" or _adoxio_licencetype_value eq {s119TypeId} and statuscode eq 1";
            }


            string[] licenseExpand = { "adoxio_LicenceType" };

            try
            {
                licences = _dynamics.Licenceses.Get(filter: licenseFilter, expand: licenseExpand).Value;
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, "Error getting licenses");
                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine("Error getting licenses");
                    hangfireContext.WriteLine("Request:");
                    hangfireContext.WriteLine(httpOperationException.Request.Content);
                    hangfireContext.WriteLine("Response:");
                    hangfireContext.WriteLine(httpOperationException.Response.Content);
                }

                throw new Exception("Unable to get licences");
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Unexpected error getting establishment map data.");
            }

            if (licences != null)
            {
                foreach (var license in licences)
                {
                    if (license.AdoxioLicenceType != null &&
                        (license.AdoxioLicenceType.AdoxioName.Equals("Cannabis Retail Store") || license.AdoxioLicenceType.AdoxioName.Equals("Section 119 Authorization")) &&
                        license._adoxioEstablishmentValue != null)
                    {
                        var establishment = _dynamics.GetEstablishmentById(license._adoxioEstablishmentValue);

                        if (establishment != null && (redoGeocoded || establishment.AdoxioLatitude == null))
                        {
                            await GeocodeEstablishment(hangfireContext, establishment);
                        }
                    }
                }
            }

            // second pass to get BC Cannabis Stores.

            IList <MicrosoftDynamicsCRMadoxioEstablishment> establishments = null;
            string establishmentFilter = "adoxio_name eq 'BC Cannabis Store'";

            try
            {
                establishments = _dynamics.Establishments.Get(filter: establishmentFilter).Value;
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, "Error getting establishments");
                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine("Error getting establishments");
                    hangfireContext.WriteLine("Request:");
                    hangfireContext.WriteLine(httpOperationException.Request.Content);
                    hangfireContext.WriteLine("Response:");
                    hangfireContext.WriteLine(httpOperationException.Response.Content);
                }

                throw new Exception("Unable to get establishments");
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Unexpected error getting establishment map data.");
            }
            if (establishments != null)
            {
                foreach (var establishment in establishments)
                {
                    if (establishment != null && (redoGeocoded || establishment.AdoxioLatitude == null))
                    {
                        await GeocodeEstablishment(hangfireContext, establishment);
                    }
                }
            }


            _logger.LogInformation("End of GeocodeEstablishments job.");
            if (hangfireContext != null)
            {
                hangfireContext.WriteLine("End of GeocodeEstablishments job.");
            }
        }
Beispiel #7
0
        public async Task <IActionResult> CreateApplication([FromBody] ViewModels.Application item)
        {
            // for association with current user
            string       userJson     = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(userJson);
            int          count        = GetSubmittedCountByApplicant(userSettings.AccountId);

            count += GetApprovedLicenceCountByApplicant(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
            {
                // set license type relationship
                if (!string.IsNullOrEmpty(item.LicenseType))
                {
                    var adoxioLicencetype = _dynamicsClient.GetAdoxioLicencetypeByName(item.LicenseType);
                    adoxioApplication.AdoxioLicenceTypeODataBind = _dynamicsClient.GetEntityURI("adoxio_licencetypes", adoxioLicencetype.AdoxioLicencetypeid);
                }

                // set account relationship
                adoxioApplication.AdoxioApplicantODataBind = _dynamicsClient.GetEntityURI("accounts", userSettings.AccountId);

                // set applicaiton type relationship
                var applicationType = _dynamicsClient.GetApplicationTypeByName(item.ApplicationType.Name);
                adoxioApplication.AdoxioApplicationTypeIdODataBind = _dynamicsClient.GetEntityURI("adoxio_applicationtypes", applicationType.AdoxioApplicationtypeid);

                if (item.ApplicationType.Name == "Marketing")
                {
                    // create tiedhouse relationship
                    adoxioApplication.AdoxioApplicationAdoxioTiedhouseconnectionApplication = new List <MicrosoftDynamicsCRMadoxioTiedhouseconnection> {
                        new MicrosoftDynamicsCRMadoxioTiedhouseconnection()
                        {
                            AdoxioConnectiontype = (int?)TiedHouseConnectionType.Marketer
                        }
                    };
                }

                // create application
                adoxioApplication = _dynamicsClient.Applications.Create(adoxioApplication);
            }
            catch (HttpOperationException httpOperationException)
            {
                string applicationId = _dynamicsClient.GetCreatedRecord(httpOperationException, null);
                if (!string.IsNullOrEmpty(applicationId) && Guid.TryParse(applicationId, out Guid applicationGuid))
                {
                    adoxioApplication = await _dynamicsClient.GetApplicationById(applicationGuid);
                }
                else
                {
                    _logger.LogError(httpOperationException, "Error creating application");
                    // fail if we can't create.
                    throw (httpOperationException);
                }
            }

            // in case the job number is not there, try getting the record from the server.
            if (adoxioApplication.AdoxioJobnumber == null)
            {
                _logger.LogDebug("AdoxioJobnumber is null, fetching record again.");
                Guid id = Guid.Parse(adoxioApplication.AdoxioApplicationid);
                adoxioApplication = await _dynamicsClient.GetApplicationById(id);
            }

            if (adoxioApplication.AdoxioJobnumber == null)
            {
                _logger.LogDebug("Unable to get the Job Number for the Application.");
                throw new Exception("Error creating Licence Application.");
            }

            await initializeSharepoint(adoxioApplication);

            return(new JsonResult(await adoxioApplication.ToViewModel(_dynamicsClient)));
        }
Beispiel #8
0
        public async Task CheckForNewLicences(PerformContext hangfireContext)
        {
            IDynamicsClient dynamicsClient = DynamicsSetupUtil.SetupDynamics(_configuration);

            if (hangfireContext != null)
            {
                hangfireContext.WriteLine("Starting check for new OneStop queue items job.");
            }
            IList <MicrosoftDynamicsCRMadoxioOnestopmessageitem> result;

            try
            {
                string        filter   = "adoxio_datetimesent eq null";
                List <string> _orderby = new List <String>()
                {
                    "createdon"
                };

                result = dynamicsClient.Onestopmessageitems.Get(filter: filter, orderby: _orderby).Value;
            }
            catch (HttpOperationException odee)
            {
                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine("Error getting Licences");
                    hangfireContext.WriteLine("Request:");
                    hangfireContext.WriteLine(odee.Request.Content);
                    hangfireContext.WriteLine("Response:");
                    hangfireContext.WriteLine(odee.Response.Content);
                }

                // fail if we can't get results.
                throw (odee);
            }

            int currentItem = 0;

            // now for each one process it.
            foreach (var queueItem in result)
            {
                if (!string.IsNullOrEmpty(queueItem._adoxioLicenceValue))
                {
                    var item = dynamicsClient.GetLicenceByIdWithChildren(queueItem._adoxioLicenceValue);

                    string licenceId = item.AdoxioLicencesid;
                    try
                    {
                        switch ((OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription)
                        {
                        case OneStopHubStatusChange.Issued:
                        case OneStopHubStatusChange.TransferComplete:
                            if ((OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription ==
                                OneStopHubStatusChange.TransferComplete)
                            {
                                // send a change status to the old licensee
                                await SendChangeStatusRest(hangfireContext, licenceId,
                                                           (OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription,
                                                           queueItem.AdoxioOnestopmessageitemid);
                            }


                            // determine if it is an Agent licence type.
                            bool isAgentLicenceType = false;
                            var  agentLicenceType   = dynamicsClient.GetAdoxioLicencetypeByName("Agent");
                            if (agentLicenceType != null && item._adoxioLicencetypeValue == agentLicenceType.AdoxioLicencetypeid)
                            {
                                isAgentLicenceType = true;
                            }

                            // Do not attempt to send licence records that have no establishment (for example, Marketer Licence records)
                            if (item.AdoxioEstablishment != null || isAgentLicenceType)
                            {
                                string programAccountCode = "001";
                                if (item.AdoxioBusinessprogramaccountreferencenumber != null)
                                {
                                    programAccountCode = item.AdoxioBusinessprogramaccountreferencenumber;
                                }

                                // set the maximum code.
                                string cacheKey = "_BPAR_" + item.AdoxioLicencesid;
                                string suffix   = programAccountCode.TrimStart('0');
                                if (int.TryParse(suffix, out int newNumber))
                                {
                                    newNumber += 10;     // 10 tries.
                                }
                                else
                                {
                                    newNumber = 10;
                                }

                                _cache.Set(cacheKey, newNumber);

                                if (hangfireContext != null)
                                {
                                    hangfireContext.WriteLine($"SET key {cacheKey} to {newNumber}");
                                }

                                await SendProgramAccountRequestREST(hangfireContext, licenceId, suffix,
                                                                    queueItem.AdoxioOnestopmessageitemid);
                            }

                            break;

                        case OneStopHubStatusChange.Cancelled:
                        case OneStopHubStatusChange.EnteredDormancy:
                        case OneStopHubStatusChange.DormancyEnded:
                        case OneStopHubStatusChange.Expired:
                        case OneStopHubStatusChange.CancellationRemoved:
                        case OneStopHubStatusChange.Renewed:
                        case OneStopHubStatusChange.Suspended:
                        case OneStopHubStatusChange.SuspensionEnded:

                            await SendChangeStatusRest(hangfireContext, licenceId,
                                                       (OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription,
                                                       queueItem.AdoxioOnestopmessageitemid);

                            break;

                        case OneStopHubStatusChange.ChangeOfAddress:
                            await SendChangeAddressRest(hangfireContext, licenceId,
                                                        queueItem.AdoxioOnestopmessageitemid);

                            break;

                        case OneStopHubStatusChange.ChangeOfName:
                            await SendChangeNameRest(hangfireContext, licenceId,
                                                     queueItem.AdoxioOnestopmessageitemid, false);

                            break;

                        case OneStopHubStatusChange.LicenceDeemedAtTransfer:
                            await SendChangeNameRest(hangfireContext, licenceId,
                                                     queueItem.AdoxioOnestopmessageitemid, true);

                            break;
                        }

                        currentItem++;
                    }
                    catch (Exception e)
                    {
                        Log.Logger.Error(e, "Unexpected Error while processing item.");
                    }

                    if (currentItem > maxLicencesPerInterval)
                    {
                        break; // exit foreach
                    }
                }
            }

            hangfireContext.WriteLine("End of check for new OneStop queue items");
        }