Beispiel #1
0
        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);
        }
        public JsonResult GetCurrentSecurityScreeningSummaryNew()
        {
            // get the current user.
            UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor);

            // check that the session is setup correctly.
            userSettings.Validate();

            // get data for the current account.
            string currentAccountId = userSettings.AccountId;

            var contacts = _dynamicsClient.GetLEConnectionsForAccount(currentAccountId, _logger, _configuration);
            List <SecurityScreeningStatusItem> securityItems = GetConnectionsScreeningData(contacts);

            // get the current user's applications and licences
            var licences     = _dynamicsClient.GetLicensesByLicencee(_cache, currentAccountId);
            var applications = _dynamicsClient.GetApplicationsForLicenceByApplicant(currentAccountId);

            SecurityScreeningSummary result = new SecurityScreeningSummary();

            // determine how many of each licence there are.
            int cannabisLicenceCount = 0;
            int liquorLicenceCount   = 0;

            if (licences != null && licences.Count() > 0)
            {
                cannabisLicenceCount = licences.Count(x => x.AdoxioLicenceType.AdoxioName.ToUpper().Contains("CANNABIS"));
                liquorLicenceCount   = licences.Count() - cannabisLicenceCount;
            }

            // determine how many applications of each type there are.
            int cannabisApplicationCount = 0;
            int liquorApplicationCount   = 0;

            if (applications != null && applications.Count() > 0)
            {
                cannabisApplicationCount = applications.Count(x => x.AdoxioApplicationTypeId != null && x.AdoxioApplicationTypeId.AdoxioName != null && x.AdoxioApplicationTypeId.AdoxioName.ToUpper().Contains("CANNABIS"));
                liquorApplicationCount   = applications.Count() - cannabisApplicationCount;
            }


            if (cannabisLicenceCount > 0 || cannabisApplicationCount > 0)
            {
                var data = securityItems.Select(item =>
                {
                    item.IsComplete = (item.Contact?.AdoxioCascomplete == (int)YesNoOptions.Yes);
                    return(item);
                });
                result.Cannabis = new SecurityScreeningCategorySummary()
                {
                    CompletedItems   = data.Where(item => item.IsComplete).ToList(),
                    OutstandingItems = data.Where(item => !item.IsComplete).ToList()
                };
            }

            if (liquorLicenceCount > 0 || liquorApplicationCount > 0)
            {
                var data = securityItems.Select(item =>
                {
                    item.IsComplete = (item.Contact?.AdoxioPhscomplete == (int)YesNoOptions.Yes);
                    return(item);
                });
                result.Liquor = new SecurityScreeningCategorySummary()
                {
                    CompletedItems   = data.Where(item => item.IsComplete).ToList(),
                    OutstandingItems = data.Where(item => !item.IsComplete).ToList()
                };
            }

            return(new JsonResult(result));
        }