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.Approved}";
                filter += $" and statuscode ne {(int)AdoxioApplicationStatusCodes.Refused}";
                filter += $" and statuscode ne {(int)AdoxioApplicationStatusCodes.TerminatedAndRefunded}";

                var applicationType = _dynamicsClient.GetApplicationTypeByName("Cannabis Retail Store");
                if (applicationType != null)
                {
                    filter += $" and _adoxio_applicationtypeid_value eq {applicationType.AdoxioApplicationtypeid} ";
                }

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

            if (!_cache.TryGetValue(cacheKey, out result))
            {
                try
                {
                    result = _dynamicsClient.GetApplicationTypeByName(name)?.AdoxioApplicationtypeid;
                    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);
        }
        public static bool IsEligibilityCheckRequired(string accountId, IConfiguration config, IDynamicsClient dynamics)
        {
            if (config["FEATURE_ELIGIBILITY"] == null || string.IsNullOrEmpty(accountId))
            {
                return(false);
            }

            bool cannabisApplicationInProgress = false;
            var  applicationType = dynamics.GetApplicationTypeByName("Cannabis Retail Store");

            if (applicationType == null)
            {
                return(false);
            }
            string filter = $"_adoxio_applicant_value eq {accountId} and _adoxio_applicationtypeid_value eq {applicationType.AdoxioApplicationtypeid} and ( statuscode eq {(int)AdoxioApplicationStatusCodes.InProgress} or statuscode eq {(int)AdoxioApplicationStatusCodes.Intake} or statuscode eq {(int)AdoxioApplicationStatusCodes.UnderReview} )";
            MicrosoftDynamicsCRMadoxioApplicationCollection dynamicsApplicationListCollection = dynamics.Applications.Get(filter: filter);

            if (dynamicsApplicationListCollection.Value.Count > 0)
            {
                cannabisApplicationInProgress = true;
            }
            try
            {
                MicrosoftDynamicsCRMaccount account = dynamics.Accounts.GetByKey(accountId);
                return((account.AdoxioIseligibilitycertified == null || account.AdoxioIseligibilitycertified == false) && cannabisApplicationInProgress);
            }
            catch (HttpOperationException)
            {
                return(false);
            }
        }
        public ActionResult GetApplicationTypeByName([FromRoute] string name)
        {
            var applicationType = _dynamicsClient.GetApplicationTypeByName(name);

            if (applicationType == null)
            {
                return(new NotFoundResult());
            }

            return(new JsonResult(applicationType.ToViewModel()));
        }
Beispiel #5
0
        public static bool IsEligibilityCheckRequired(string accountId, IConfiguration config, IDynamicsClient dynamics)
        {
            // if the eligibility feature is disabled or the accountID isn't created (yet?)
            if (config["FEATURE_ELIGIBILITY"] == null || string.IsNullOrEmpty(accountId) || accountId.Equals("00000000-0000-0000-0000-000000000000"))
            {
                return(false);
            }

            // keep track of whether there are cannabis applications in progress
            bool cannabisApplicationInProgress = false;
            var  applicationType = dynamics.GetApplicationTypeByName("Cannabis Retail Store");

            // if they have no cannabis apps (regardless of state)
            if (applicationType == null)
            {
                // then we don't need to question eligibility
                return(false);
            }
            // look for cannabis apps that are in progress (also intake, or under review)
            string filter = $"_adoxio_applicant_value eq {accountId} and _adoxio_applicationtypeid_value eq {applicationType.AdoxioApplicationtypeid} and ( statuscode eq {(int)AdoxioApplicationStatusCodes.InProgress} or statuscode eq {(int)AdoxioApplicationStatusCodes.Intake} or statuscode eq {(int)AdoxioApplicationStatusCodes.UnderReview} )";
            MicrosoftDynamicsCRMadoxioApplicationCollection dynamicsApplicationListCollection = dynamics.Applications.Get(filter: filter);

            if (dynamicsApplicationListCollection.Value.Count > 0)
            {
                // we found one (or more)
                cannabisApplicationInProgress = true;
            }

            // next, check the account to see if they've answered the eligibility question
            try
            {
                // if they  have a cannabis application in progress and they have not yet certified, then they will be asked to certify
                if (!string.IsNullOrEmpty(accountId) && Guid.Parse(accountId) != Guid.Empty)
                {
                    MicrosoftDynamicsCRMaccount account = dynamics.Accounts.GetByKey(accountId);
                    return((account.AdoxioIseligibilitycertified == null || account.AdoxioIseligibilitycertified == false) && cannabisApplicationInProgress);
                }
            }
            catch (HttpOperationException)
            {
                // if we fail, then all G.
            }
            return(false);
        }
Beispiel #6
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)));
            }
        }