public async Task <IActionResult> GetInvoice(string id)
        {
            if (TestUtility.InUnitTestMode())
            {
                ViewModels.Invoice result = null;
                // query the Dynamics system to get the invoice record.
                if (string.IsNullOrEmpty(id))
                {
                    return(new NotFoundResult());
                }

                // get the current user.
                UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor);

                Guid adoxio_legalentityid           = new Guid(id);
                MicrosoftDynamicsCRMinvoice invoice = await _dynamicsClient.GetInvoiceById(adoxio_legalentityid);

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

                // setup the related account.
                if (invoice._accountidValue != null)
                {
                    Guid accountId = Guid.Parse(invoice._accountidValue);
                    invoice.CustomeridAccount = await _dynamicsClient.GetAccountByIdAsync(accountId);
                }

                result = invoice.ToViewModel();

                return(new JsonResult(result));
            }
            return(new NotFoundResult());
        }
Пример #2
0
        /// <summary>
        /// Returns the folder name for a given entity
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <param name="getFromDocumentLocation"></param>
        /// <param name="_dynamicsClient"></param>
        /// <returns></returns>
        public static async Task <string> GetFolderName(this IDynamicsClient _dynamicsClient, string entityName, string entityId, bool getFromDocumentLocation = true)
        {
            string folderName = null;

            if (getFromDocumentLocation)
            {
                folderName = _dynamicsClient.GetEntitySharePointDocumentLocation(entityName, entityId);
            }

            if (folderName == null)
            {
                switch (entityName.ToLower())
                {
                case "account":
                    var account = await _dynamicsClient.GetAccountByIdAsync(Guid.Parse(entityId)).ConfigureAwait(true);

                    folderName = account.GetDocumentFolderName();
                    break;

                case "application":
                    var application = await _dynamicsClient.GetApplicationById(Guid.Parse(entityId)).ConfigureAwait(true);

                    folderName = application.GetDocumentFolderName();
                    break;

                case "contact":
                    var contact = await _dynamicsClient.GetContactById(Guid.Parse(entityId)).ConfigureAwait(true);

                    folderName = contact.GetDocumentFolderName();
                    break;

                case "worker":
                    var worker = await _dynamicsClient.GetWorkerById(Guid.Parse(entityId)).ConfigureAwait(true);

                    folderName = worker.GetDocumentFolderName();
                    break;

                case "event":
                    var eventEntity = _dynamicsClient.GetEventById(Guid.Parse(entityId));
                    folderName = eventEntity.GetDocumentFolderName();
                    break;

                case "licence":
                    var licenceEntity = _dynamicsClient.GetLicenceById(Guid.Parse(entityId));
                    folderName = licenceEntity.GetDocumentFolderName();
                    break;

                case "specialevent":
                    var entity = _dynamicsClient.GetSpecialEventById(entityId);
                    folderName = entity.GetDocumentFolderName();
                    break;
                }
            }

            return(folderName);
        }
        /// <summary>
        /// Returns true if the current user can access the entity
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <param name="isDelete">Some access rules are different for deletes</param>
        /// <returns></returns>
        private async Task <bool> CanAccessEntity(string entityName, string entityId, bool isDelete = false)
        {
            var result = false;
            var id     = Guid.Parse(entityId);

            switch (entityName.ToLower())
            {
            case "account":
                var account = await _dynamicsClient.GetAccountByIdAsync(id).ConfigureAwait(true);

                result = account != null && CurrentUserHasAccessToAccount(account.Accountid);
                break;

            case "application":
                var application = await _dynamicsClient.GetApplicationById(id).ConfigureAwait(true);

                result = application != null && CurrentUserHasAccessToAccount(application._adoxioApplicantValue);
                var allowLGAccess = await CurrentUserIsLGForApplication(application);

                result = result || allowLGAccess && !isDelete;
                break;

            case "contact":
                var contact = await _dynamicsClient.GetContactById(id).ConfigureAwait(true);

                result = contact != null && CurrentUserHasAccessToContactOwnedBy(contact.Contactid);
                break;

            case "worker":
                var worker = await _dynamicsClient.GetWorkerById(id).ConfigureAwait(true);

                result = worker != null && CurrentUserHasAccessToContactOwnedBy(worker._adoxioContactidValue);
                break;

            case "event":
                var eventEntity = _dynamicsClient.GetEventById(id);
                result = eventEntity != null && CurrentUserHasAccessToAccount(eventEntity._adoxioAccountValue);
                break;
            }
            return(result);
        }
Пример #4
0
        public async Task <IActionResult> SubmitEligibilityForm([FromBody] EligibilityForm form)
        {
            // get the current user.
            UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor);

            if (userSettings.AccountId != null && userSettings.AccountId.Length > 0)
            {
                Guid accountId = new Guid(userSettings.AccountId);
                MicrosoftDynamicsCRMaccount adoxioAccount = await _dynamicsClient.GetAccountByIdAsync(accountId);

                if (adoxioAccount == null)
                {
                    _logger.LogError($"Account {accountId} NOT found.");
                    return(new NotFoundResult());
                }
                adoxioAccount = new MicrosoftDynamicsCRMaccount();
                if (form.IsEligibilityCertified)
                {
                    adoxioAccount.AdoxioIsconnectiontounlicensedstore         = form.IsConnectedToUnlicencedStore;
                    adoxioAccount.AdoxioNamelocationunlicensedretailer        = form.NameLocationUnlicencedRetailer;
                    adoxioAccount.AdoxioIsretailerstilloperating              = form.IsRetailerStillOperating;
                    adoxioAccount.AdoxioDateoperationsceased                  = form.DateOperationsCeased;
                    adoxioAccount.AdoxioIsinvolvedillegaldistribution         = form.IsInvolvedIllegalDistribution;
                    adoxioAccount.AdoxioIllegaldistributioninvolvementdetails = form.IllegalDistributionInvolvementDetails;
                    adoxioAccount.AdoxioNamelocationretailer                  = form.NameLocationRetailer;
                    adoxioAccount.AdoxioIsinvolvementcontinuing               = form.IsInvolvementContinuing;
                    adoxioAccount.AdoxioDateinvolvementceased                 = form.DateInvolvementCeased;
                    adoxioAccount.AdoxioIseligibilitycertified                = form.IsEligibilityCertified;
                    adoxioAccount.AdoxioEligibilitysignature                  = form.EligibilitySignature;
                    adoxioAccount.AdoxioDatesignordismissed = form.DateSignedOrDismissed;
                }
                else
                {
                    adoxioAccount.AdoxioIseligibilitycertified = false;
                    adoxioAccount.AdoxioDatesignordismissed    = form.DateSignedOrDismissed;
                }
                _dynamicsClient.Accounts.Update(accountId.ToString(), adoxioAccount);
                return(new JsonResult("Ok"));
            }
            return(new NotFoundResult());
        }
        public async static Task <ViewModels.Application> ToViewModel(this MicrosoftDynamicsCRMadoxioApplication dynamicsApplication, IDynamicsClient dynamicsClient, IMemoryCache cache, ILogger logger)
        {
            ViewModels.Application applicationVM = new ViewModels.Application()
            {
                Name      = dynamicsApplication.AdoxioName,
                JobNumber = dynamicsApplication.AdoxioJobnumber,
                //get establishment name and address
                EstablishmentName              = dynamicsApplication.AdoxioEstablishmentpropsedname,
                EstablishmentAddressStreet     = dynamicsApplication.AdoxioEstablishmentaddressstreet,
                EstablishmentAddressCity       = dynamicsApplication.AdoxioEstablishmentaddresscity,
                EstablishmentAddressPostalCode = dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentAddress           = dynamicsApplication.AdoxioEstablishmentaddressstreet
                                                 + ", " + dynamicsApplication.AdoxioEstablishmentaddresscity
                                                 + " " + dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentPhone    = dynamicsApplication.AdoxioEstablishmentphone,
                EstablishmentEmail    = dynamicsApplication.AdoxioEstablishmentemail,
                FederalProducerNames  = dynamicsApplication.AdoxioFederalproducernames,
                IsApplicationComplete = (GeneralYesNo?)dynamicsApplication.AdoxioIsapplicationcomplete,

                RenewalCriminalOffenceCheck     = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalcriminaloffencecheck,
                RenewalUnreportedSaleOfBusiness = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalunreportedsaleofbusiness,
                RenewalBusinessType             = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalbusinesstype,
                RenewalTiedhouse            = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaltiedhouse,
                RenewalOrgLeadership        = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalorgleadership,
                Renewalkeypersonnel         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalkeypersonnel,
                RenewalShareholders         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalshareholders,
                RenewalOutstandingFines     = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaloutstandingfines,
                RenewalBranding             = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalbranding,
                RenewalSignage              = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalsignage,
                RenewalEstablishmentAddress = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalestablishmentaddress,
                RenewalValidInterest        = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalvalidinterest,
                RenewalZoning            = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalzoning,
                RenewalFloorPlan         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalfloorplan,
                RenewalSiteMap           = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalsitemap,
                TiedhouseFederalInterest = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaltiedhousefederalinterest,
                RenewalDUI        = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaldui,
                RenewalThirdParty = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalthirdparty,

                AuthorizedToSubmit = dynamicsApplication.AdoxioAuthorizedtosubmit,
                SignatureAgreement = dynamicsApplication.AdoxioSignatureagreement,

                LicenceFeeInvoicePaid = (dynamicsApplication.AdoxioLicencefeeinvoicepaid != null && dynamicsApplication.AdoxioLicencefeeinvoicepaid == true),

                // set a couple of read-only flags to indicate status
                IsPaid = (dynamicsApplication.AdoxioPaymentrecieved != null && (bool)dynamicsApplication.AdoxioPaymentrecieved),

                IndigenousNationId   = dynamicsApplication._adoxioLocalgovindigenousnationidValue,
                PoliceJurisdictionId = dynamicsApplication._adoxioPolicejurisdictionidValue,

                //get parcel id
                EstablishmentParcelId = dynamicsApplication.AdoxioEstablishmentparcelid,

                //get additional property info
                AdditionalPropertyInformation = dynamicsApplication.AdoxioAdditionalpropertyinformation,
                AdoxioInvoiceId = dynamicsApplication._adoxioInvoiceValue,

                PaymentReceivedDate = dynamicsApplication.AdoxioPaymentreceiveddate,
                Description1        = dynamicsApplication.AdoxioDescription1,
                Description2        = dynamicsApplication.AdoxioDescription2,

                //get contact details
                ContactPersonFirstName = dynamicsApplication.AdoxioContactpersonfirstname,
                ContactPersonLastName  = dynamicsApplication.AdoxioContactpersonlastname,
                ContactPersonRole      = dynamicsApplication.AdoxioRole,
                ContactPersonEmail     = dynamicsApplication.AdoxioEmail,
                ContactPersonPhone     = dynamicsApplication.AdoxioContactpersonphone,

                //get record audit info
                CreatedOn  = dynamicsApplication.Createdon,
                ModifiedOn = dynamicsApplication.Modifiedon,

                //store opening
                IsReadyWorkers                  = dynamicsApplication.AdoxioIsreadyworkers,
                IsReadyNameBranding             = dynamicsApplication.AdoxioIsreadynamebranding,
                IsReadyDisplays                 = dynamicsApplication.AdoxioIsreadydisplays,
                IsReadyIntruderAlarm            = dynamicsApplication.AdoxioIsreadyintruderalarm,
                IsReadyFireAlarm                = dynamicsApplication.AdoxioIsreadyfirealarm,
                IsReadyLockedCases              = dynamicsApplication.AdoxioIsreadylockedcases,
                IsReadyLockedStorage            = dynamicsApplication.AdoxioIsreadylockedstorage,
                IsReadyPerimeter                = dynamicsApplication.AdoxioIsreadyperimeter,
                IsReadyRetailArea               = dynamicsApplication.AdoxioIsreadyretailarea,
                IsReadyStorage                  = dynamicsApplication.AdoxioIsreadystorage,
                IsReadyExtranceExit             = dynamicsApplication.AdoxioIsreadyentranceexit,
                IsReadySurveillanceNotice       = dynamicsApplication.AdoxioIsreadysurveillancenotice,
                IsReadyProductNotVisibleOutside = dynamicsApplication.AdoxioIsreadyproductnotvisibleoutside,
                IsLocatedInGroceryStore         = dynamicsApplication.AdoxioIslocatedingrocerystore,
                Establishmentopeningdate        = dynamicsApplication.AdoxioEstablishmentopeningdate,
                IsReadyValidInterest            = dynamicsApplication.AdoxioIsreadyvalidinterest,

                IsHasPatio = dynamicsApplication.AdoxioIshaspatio,

                // LgInName
                LGNameOfOfficial         = dynamicsApplication.AdoxioLgnameofofficial,
                LGTitlePosition          = dynamicsApplication.AdoxioLgtitleposition,
                LGContactPhone           = dynamicsApplication.AdoxioLgcontactphone,
                LGContactEmail           = dynamicsApplication.AdoxioLgcontactemail,
                LGDecisionSubmissionDate = dynamicsApplication.AdoxioLgdecisionsubmissiondate,
                LgInName           = dynamicsApplication?.AdoxioLocalgovindigenousnationid?.AdoxioName,
                LGApprovalDecision = (LGDecision?)dynamicsApplication.AdoxioLgapprovaldecision,
                LgZoning           = (Zoning?)dynamicsApplication.AdoxioLgzoning,
                LGDecisionComments = dynamicsApplication.AdoxioLgdecisioncomments,

                // Catering fields.

                PreviousApplicationDetails = dynamicsApplication.AdoxioPreviouslicenceapplicationdetails,

                LiquorIndustryConnectionsDetails = dynamicsApplication.AdoxioLiquorindustryconnectionsdetails,

                OtherBusinessesDetails = dynamicsApplication.AdoxioOtherbusinesssamelocationdetails,
                ServiceAreas           = new List <CapacityArea>(),
                OutsideAreas           = new List <CapacityArea>(),
                CapacityArea           = new List <CapacityArea>(),

                // Manufacturing fields

                IsPackaging = dynamicsApplication.AdoxioIspackaging,

                MfgAcresOfFruit           = dynamicsApplication.AdoxioMfgacresoffruit,
                MfgAcresOfGrapes          = dynamicsApplication.AdoxioMfgacresofgrapes,
                MfgAcresOfHoney           = dynamicsApplication.AdoxioMfgacresofhoney,
                MfgMeetsProductionMinimum = dynamicsApplication.AdoxioMfgmeetsproductionminimum,
                MfgStepBlending           = dynamicsApplication.AdoxioMfgstepblending,
                MfgStepCrushing           = dynamicsApplication.AdoxioMfgstepcrushing,
                MfgStepFiltering          = dynamicsApplication.AdoxioMfgstepfiltering,
                MfgStepSecFermOrCarb      = dynamicsApplication.AdoxioMfgstepsecfermorcarb,
                IsOwnerBusiness           = dynamicsApplication.AdoxioIsownerbusiness,
                HasValidInterest          = dynamicsApplication.AdoxioIsownerhasvalidinterest,
                WillHaveValidInterest     = dynamicsApplication.AdoxioIsownerwillhavevalidinterest,
                ZoningStatus = dynamicsApplication.AdoxioZoningstatus,


                PidList             = dynamicsApplication.AdoxioPidlist,
                IsPermittedInZoning = dynamicsApplication.AdoxioIspermittedinzoning,

                // Manufacturing structural change fields

                PatioCompDescription          = dynamicsApplication.AdoxioPatiocompdescription,
                PatioLocationDescription      = dynamicsApplication.AdoxioPatiolocationdescription,
                PatioAccessDescription        = dynamicsApplication.AdoxioPatioaccessdescription,
                PatioIsLiquorCarried          = dynamicsApplication.AdoxioPatioisliquorcarried,
                PatioLiquorCarriedDescription = dynamicsApplication.AdoxioPatioliquorcarrieddescription,
                PatioAccessControlDescription = dynamicsApplication.AdoxioPatioaccesscontroldescription,
                IsAlr           = dynamicsApplication.AdoxioProposedestablishmentisalr.HasValue && (bool)dynamicsApplication.AdoxioProposedestablishmentisalr,
                HasCoolerAccess = dynamicsApplication.AdoxioHascooleraccess.HasValue && (bool)dynamicsApplication.AdoxioHascooleraccess
            };


            // mfg fields

            if (dynamicsApplication.AdoxioMfgpipedinproduct != null)
            {
                applicationVM.MfgPipedInProduct = (YesNoNotApplicable?)dynamicsApplication.AdoxioMfgpipedinproduct;
            }
            if (dynamicsApplication.AdoxioMfgbrewpubonsite != null)
            {
                applicationVM.MfgBrewPubOnSite = (YesNoNotApplicable?)dynamicsApplication.AdoxioMfgbrewpubonsite;
            }
            if (dynamicsApplication.AdoxioMfgusesneutralgrainspirits != null)
            {
                applicationVM.MfgUsesNeutralGrainSpirits = (YesNoNotApplicable)dynamicsApplication.AdoxioMfgusesneutralgrainspirits;
            }


            if (dynamicsApplication.AdoxioLocatedabovedescription != null)
            {
                applicationVM.LocatedAboveDescription = dynamicsApplication.AdoxioLocatedabovedescription;
            }

            if (dynamicsApplication.AdoxioPatioservicebar != null)
            {
                applicationVM.PatioServiceBar = dynamicsApplication.AdoxioPatioservicebar;
            }

            // Catering yes / no fields
            if (dynamicsApplication.AdoxioPreviouslicenceapplication != null)
            {
                applicationVM.PreviousApplication = dynamicsApplication.AdoxioPreviouslicenceapplication;
            }

            if (dynamicsApplication.AdoxioRuralagencystoreappointment != null)
            {
                applicationVM.RuralAgencyStoreAppointment = dynamicsApplication.AdoxioRuralagencystoreappointment;
            }

            if (dynamicsApplication.AdoxioLiquorindustryconnections != null)
            {
                applicationVM.LiquorIndustryConnections = dynamicsApplication.AdoxioLiquorindustryconnections;
            }

            if (dynamicsApplication.AdoxioOtherbusinessesatthesamelocation != null)
            {
                applicationVM.OtherBusinesses = dynamicsApplication.AdoxioOtherbusinessesatthesamelocation;
            }


            // id
            if (dynamicsApplication.AdoxioApplicationid != null)
            {
                applicationVM.Id = dynamicsApplication.AdoxioApplicationid.ToString();

                // service areas
                var filter = $"_adoxio_applicationid_value eq {dynamicsApplication.AdoxioApplicationid}";
                try
                {
                    IList <MicrosoftDynamicsCRMadoxioServicearea> areas = dynamicsClient.Serviceareas.Get(filter: filter).Value;
                    foreach (MicrosoftDynamicsCRMadoxioServicearea area in areas)
                    {
                        if (area.AdoxioAreacategory == (int?)AdoxioAreaCategories.Service)
                        {
                            applicationVM.ServiceAreas.Add(area.ToViewModel());
                        }
                        else if (area.AdoxioAreacategory == (int?)AdoxioAreaCategories.OutdoorArea)
                        {
                            applicationVM.OutsideAreas.Add(area.ToViewModel());
                        }
                        else if (area.AdoxioAreacategory == (int?)AdoxioAreaCategories.Capacity)
                        {
                            applicationVM.CapacityArea.Add(area.ToViewModel());
                        }
                    }
                }
                catch (HttpOperationException httpOperationException)
                {
                    logger.LogError(httpOperationException, "Error getting service areas.");
                }

                // service hours
                try
                {
                    var appFilter = $"_adoxio_application_value eq {dynamicsApplication.AdoxioApplicationid}";
                    IList <MicrosoftDynamicsCRMadoxioHoursofservice> hours = dynamicsClient.Hoursofservices.Get(filter: appFilter).Value;
                    if (hours.Count > 0)
                    {
                        MicrosoftDynamicsCRMadoxioHoursofservice hourEntity = hours[0];
                        applicationVM.ServiceHoursSundayOpen     = (ServiceHours?)hourEntity.AdoxioSundayopen;
                        applicationVM.ServiceHoursSundayClose    = (ServiceHours?)hourEntity.AdoxioSundayclose;
                        applicationVM.ServiceHoursMondayOpen     = (ServiceHours?)hourEntity.AdoxioMondayopen;
                        applicationVM.ServiceHoursMondayClose    = (ServiceHours?)hourEntity.AdoxioMondayclose;
                        applicationVM.ServiceHoursTuesdayOpen    = (ServiceHours?)hourEntity.AdoxioTuesdayopen;
                        applicationVM.ServiceHoursTuesdayClose   = (ServiceHours?)hourEntity.AdoxioTuesdayclose;
                        applicationVM.ServiceHoursWednesdayOpen  = (ServiceHours?)hourEntity.AdoxioWednesdayopen;
                        applicationVM.ServiceHoursWednesdayClose = (ServiceHours?)hourEntity.AdoxioWednesdayclose;
                        applicationVM.ServiceHoursThursdayOpen   = (ServiceHours?)hourEntity.AdoxioThursdayopen;
                        applicationVM.ServiceHoursThursdayClose  = (ServiceHours?)hourEntity.AdoxioThursdayclose;
                        applicationVM.ServiceHoursFridayOpen     = (ServiceHours?)hourEntity.AdoxioFridayopen;
                        applicationVM.ServiceHoursFridayClose    = (ServiceHours?)hourEntity.AdoxioFridayclose;
                        applicationVM.ServiceHoursSaturdayOpen   = (ServiceHours?)hourEntity.AdoxioSaturdayopen;
                        applicationVM.ServiceHoursSaturdayClose  = (ServiceHours?)hourEntity.AdoxioSaturdayclose;
                    }
                }
                catch (HttpOperationException httpOperationException)
                {
                    logger.LogError(httpOperationException, "Error getting service hours.");
                }
            }

            if (dynamicsApplication.Statuscode != null)
            {
                applicationVM.ApplicationStatus = (AdoxioApplicationStatusCodes)dynamicsApplication.Statuscode;
            }

            if (dynamicsApplication.AdoxioApplicanttype != null)
            {
                applicationVM.ApplicantType = (AdoxioApplicantTypeCodes)dynamicsApplication.AdoxioApplicanttype;
            }

            //get applying person from Contact entity
            if (dynamicsApplication._adoxioApplyingpersonValue != null)
            {
                Guid applyingPersonId = Guid.Parse(dynamicsApplication._adoxioApplyingpersonValue);
                var  contact          = await dynamicsClient.GetContactById(applyingPersonId);

                applicationVM.ApplyingPerson = contact.Fullname;
            }

            if (dynamicsApplication._adoxioApplicantValue != null)
            {
                var applicant = await dynamicsClient.GetAccountByIdAsync(Guid.Parse(dynamicsApplication._adoxioApplicantValue));

                applicationVM.Applicant = applicant.ToViewModel();
            }

            //get license type from Adoxio_licencetype entity
            if (dynamicsApplication._adoxioLicencetypeValue != null)
            {
                Guid adoxio_licencetypeId = Guid.Parse(dynamicsApplication._adoxioLicencetypeValue);
                var  adoxio_licencetype   = dynamicsClient.GetAdoxioLicencetypeById(adoxio_licencetypeId);
                applicationVM.LicenseType = adoxio_licencetype.AdoxioName;
            }

            // get the license sub type.

            if (dynamicsApplication._adoxioLicencesubcategoryidValue != null)
            {
                try
                {
                    var adoxioLicencesubcategory = dynamicsClient.Licencesubcategories.GetByKey(dynamicsApplication._adoxioLicencesubcategoryidValue);
                    applicationVM.LicenceSubCategory = adoxioLicencesubcategory.AdoxioName;
                }
                catch (Exception e)
                {
                    logger.LogError(e, $"Problem getting licence sub category {dynamicsApplication._adoxioLicencesubcategoryidValue}");
                }
            }

            if (dynamicsApplication.AdoxioAppchecklistfinaldecision != null)
            {
                applicationVM.AppChecklistFinalDecision = (AdoxioFinalDecisionCodes)dynamicsApplication.AdoxioAppchecklistfinaldecision;
            }

            //get payment info
            applicationVM.InvoiceTrigger = (GeneralYesNo?)dynamicsApplication.AdoxioInvoicetrigger;
            applicationVM.IsSubmitted    = (dynamicsApplication.AdoxioInvoicetrigger == 1);


            if (dynamicsApplication.AdoxioLicenceFeeInvoice != null)
            {
                applicationVM.LicenceFeeInvoice = dynamicsApplication.AdoxioLicenceFeeInvoice.ToViewModel();
            }

            if (dynamicsApplication.AdoxioAssignedLicence != null)
            {
                applicationVM.AssignedLicence = dynamicsApplication.AdoxioAssignedLicence.ToViewModel(dynamicsClient);
            }

            if (dynamicsApplication.AdoxioApplicationTypeId != null)
            {
                applicationVM.ApplicationType = dynamicsApplication.AdoxioApplicationTypeId.ToViewModel();

                if (!string.IsNullOrEmpty(applicationVM.ApplicationType.FormReference))
                {
                    applicationVM.ApplicationType.DynamicsForm = dynamicsClient.GetSystemformViewModel(cache, logger, applicationVM.ApplicationType.FormReference);
                }
            }
            if (dynamicsApplication.AdoxioApplicationAdoxioTiedhouseconnectionApplication != null)
            {
                var tiedHouse = dynamicsApplication.AdoxioApplicationAdoxioTiedhouseconnectionApplication.FirstOrDefault();
                if (tiedHouse != null)
                {
                    applicationVM.TiedHouse = tiedHouse.ToViewModel();
                }
            }

            if (dynamicsApplication.AdoxioPoliceJurisdictionId != null)
            {
                applicationVM.PoliceJurisdiction = dynamicsApplication.AdoxioPoliceJurisdictionId.ToViewModel();
            }

            if (dynamicsApplication.AdoxioLocalgovindigenousnationid != null)
            {
                var filter        = $"_adoxio_lginlinkid_value eq {dynamicsApplication.AdoxioLocalgovindigenousnationid.AdoxioLocalgovindigenousnationid} and websiteurl ne null";
                var linkedAccount = (await dynamicsClient.Accounts.GetAsync(filter: filter)).Value.FirstOrDefault();
                applicationVM.IndigenousNation = dynamicsApplication.AdoxioLocalgovindigenousnationid.ToViewModel();

                if (linkedAccount != null)
                {
                    applicationVM.IndigenousNation.WebsiteUrl = linkedAccount.Websiteurl;
                }
            }

            applicationVM.PrevPaymentFailed = (dynamicsApplication._adoxioInvoiceValue != null) && (!applicationVM.IsSubmitted);

            return(applicationVM);
        }
Пример #6
0
        /// <summary>
        /// Returns true if the current user can access the entity
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <param name="isDelete">Some access rules are different for deletes</param>
        /// <returns></returns>
        private async Task <bool> CanAccessEntity(string entityName, string entityId, string relativeUrl, bool isDelete = false)
        {
            var    result     = false;
            var    id         = Guid.Parse(entityId);
            string folderName = null;

            switch (entityName.ToLower())
            {
            case "account":
                var account = await _dynamicsClient.GetAccountByIdAsync(id).ConfigureAwait(true);

                if (account != null)
                {
                    result     = CurrentUserHasAccessToAccount(account.Accountid);
                    folderName = account.GetDocumentFolderName();
                }
                break;

            case "application":
                var application = await _dynamicsClient.GetApplicationById(id).ConfigureAwait(true);

                if (application != null)
                {
                    result = CurrentUserHasAccessToAccount(application._adoxioApplicantValue);
                    var allowLGAccess = await CurrentUserIsLGForApplication(application);

                    result     = result || allowLGAccess && !isDelete;
                    folderName = application.GetDocumentFolderName();
                }

                break;

            case "contact":
                var contact = await _dynamicsClient.GetContactById(id).ConfigureAwait(true);

                if (contact != null)
                {
                    result     = CurrentUserHasAccessToContactOwnedBy(contact.Contactid);
                    folderName = contact.GetDocumentFolderName();
                }

                break;

            case "worker":
                var worker = await _dynamicsClient.GetWorkerById(id).ConfigureAwait(true);

                if (worker != null)
                {
                    result     = CurrentUserHasAccessToContactOwnedBy(worker._adoxioContactidValue);
                    folderName = worker.GetDocumentFolderName();
                }
                break;

            case "event":
                var eventEntity = _dynamicsClient.GetEventById(id);
                if (eventEntity != null)
                {
                    result     = CurrentUserHasAccessToAccount(eventEntity._adoxioAccountValue);
                    folderName = eventEntity.GetDocumentFolderName();
                }

                break;
            }

            if (folderName != null && result && relativeUrl != null)  // do a case insensitive comparison of the first part.
            {
                int slashPos = relativeUrl.IndexOf("/");
                if (slashPos != -1 && slashPos < relativeUrl.Length)
                {
                    slashPos = relativeUrl.IndexOf("/", slashPos + 1);
                }
                result = relativeUrl.ToUpper().Substring(slashPos + 1).StartsWith(folderName.ToUpper());
            }

            return(result);
        }