public async void WorkerLicenceTest()
        {
            var parameters = new Dictionary <string, string>
            {
                { "title", "Worker_Qualification" },
                { "currentDate", DateTime.Now.ToLongDateString() },
                { "firstName", "FirstName" },
                { "middleName", "MiddleName" },
                { "lastName", "LastName" },
                { "dateOfBirth", DateTime.Now.ToString("dd/MM/yyyy") },
                { "address", "123 Main St." },
                { "city", "City" },
                { "province", "Province" },
                { "postalCode", "V091K9" },
                { "effectiveDate", DateTime.Now.ToString("dd/MM/yyyy") },
                { "expiryDate", DateTime.Now.ToString("dd/MM/yyyy") },
                { "border", "{ \"top\": \"40px\", \"right\": \"40px\", \"bottom\": \"0px\", \"left\": \"40px\" }" }
            };

            byte[] data = await _pdfClient.GetPdf(parameters, "worker_qualification_letter");

            Assert.NotNull(data);
        }
Beispiel #2
0
        public async Task <IActionResult> GetLicencePDF(string workerId)
        {
            var expand = new List <string> {
                "adoxio_ContactId",
                "adoxio_workerregistration_personalhistorysummary"
            };

            MicrosoftDynamicsCRMadoxioWorker adoxioWorker = _dynamicsClient.Workers.GetByKey(workerId, expand: expand);

            if (adoxioWorker == null)
            {
                throw new Exception("Error getting worker.");
            }

            if (!CurrentUserHasAccessToContactWorkerApplicationOwnedBy(adoxioWorker?.AdoxioContactId?.Contactid))
            {
                return(NotFound("No access to worker"));
            }

            var dateOfBirthParam = "";

            if (adoxioWorker.AdoxioDateofbirth.HasValue)
            {
                DateTime dateOfBirth = adoxioWorker.AdoxioDateofbirth.Value.DateTime;
                dateOfBirthParam = dateOfBirth.ToString("dd/MM/yyyy");
            }

            var effectiveDateParam = "";
            var securityClearance  = adoxioWorker.AdoxioWorkerregistrationPersonalhistorysummary.FirstOrDefault();

            if (securityClearance != null && securityClearance.AdoxioCompletedon.HasValue)
            {
                DateTime effectiveDate = securityClearance.AdoxioCompletedon.Value.DateTime;
                effectiveDateParam = effectiveDate.ToString("dd/MM/yyyy");
            }

            var expiryDateParam = "";

            if (securityClearance != null && securityClearance.AdoxioExpirydate.HasValue)
            {
                DateTime expiryDate = securityClearance.AdoxioExpirydate.Value.DateTime;
                expiryDateParam = expiryDate.ToString("dd/MM/yyyy");
            }

            var parameters = new Dictionary <string, string>
            {
                { "title", "Worker_Qualification" },
                { "currentDate", DateTime.Now.ToLongDateString() },
                { "firstName", adoxioWorker.AdoxioFirstname },
                { "middleName", adoxioWorker.AdoxioMiddlename },
                { "lastName", adoxioWorker.AdoxioLastname },
                { "dateOfBirth", dateOfBirthParam },
                { "address", adoxioWorker.AdoxioContactId.Address1Line1 },
                { "city", adoxioWorker.AdoxioContactId.Address1City },
                { "province", adoxioWorker.AdoxioContactId.Address1Stateorprovince },
                { "postalCode", adoxioWorker.AdoxioContactId.Address1Postalcode },
                { "effectiveDate", effectiveDateParam },
                { "expiryDate", expiryDateParam },
                { "border", "{ \"top\": \"40px\", \"right\": \"40px\", \"bottom\": \"0px\", \"left\": \"40px\" }" }
            };

            try
            {
                byte[] data = await _pdfClient.GetPdf(parameters, "worker_qualification_letter");

                return(File(data, "application/pdf"));
            }
            catch
            {
                string basePath = string.IsNullOrEmpty(Configuration["BASE_PATH"]) ? "" : Configuration["BASE_PATH"];
                basePath += "/worker-qualification/dashboard";
                return(Redirect(basePath));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> GetLicencePDF(string licenceId, string filename)
        {
            var expand = new List <string> {
                "adoxio_Licencee",
                "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence",
                "adoxio_adoxio_licences_adoxio_application_AssignedLicence",
                "adoxio_LicenceType",
                "adoxio_establishment"
            };

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

            if (adoxioLicense == null)
            {
                throw new Exception("Error getting license.");
            }

            if (CurrentUserHasAccessToLicenseOwnedBy(adoxioLicense.AdoxioLicencee.Accountid))
            {
                var effectiveDateParam = "";
                if (adoxioLicense.AdoxioEffectivedate.HasValue)
                {
                    DateTime effectiveDate = adoxioLicense.AdoxioEffectivedate.Value.DateTime;
                    effectiveDateParam = effectiveDate.ToString("MMMM dd, yyyy");
                }

                var expiraryDateParam = "";
                if (adoxioLicense.AdoxioExpirydate.HasValue)
                {
                    DateTime expiryDate = adoxioLicense.AdoxioExpirydate.Value.DateTime;
                    expiraryDateParam = expiryDate.ToString("MMMM dd, yyyy");
                }

                var termsAndConditions = "";
                foreach (var item in adoxioLicense.AdoxioAdoxioLicencesAdoxioApplicationtermsconditionslimitationLicence)
                {
                    termsAndConditions += $"<li>{item.AdoxioTermsandconditions}</li>";
                }

                var application = adoxioLicense?.AdoxioAdoxioLicencesAdoxioApplicationAssignedLicence?.FirstOrDefault();
                var storeHours  = $@"
                <tr>
                    <td>Open</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                </tr>                
                <tr>
                    <td>Close</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                </tr>";
                if (application.AdoxioServicehoursstandardhours != true && adoxioLicense.AdoxioLicenceType.AdoxioName == "Cannabis Retail Store")
                {
                    storeHours = $@"
                <tr>
                    <td>Open</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursmondayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourstuesdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourswednesdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursthursdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursfridayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssaturdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssundayopen)}</td>
                </tr>                
                <tr>
                    <td>Close</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursmondayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourstuesdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourswednesdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursthursdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursfridayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssaturdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssundayclose)}</td>
                </tr>";
                }
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                if (adoxioLicense.AdoxioLicenceType.AdoxioName == "Cannabis Retail Store")
                {
                    parameters = new Dictionary <string, string>
                    {
                        { "title", "Canabis_License" },
                        { "licenceNumber", adoxioLicense.AdoxioLicencenumber },
                        { "establishmentName", adoxioLicense.AdoxioEstablishment.AdoxioName },
                        { "establishmentStreet", adoxioLicense.AdoxioEstablishment.AdoxioAddressstreet },
                        { "establishmentCity", adoxioLicense.AdoxioEstablishment.AdoxioAddresscity + ", B.C." },
                        { "establishmentPostalCode", adoxioLicense.AdoxioEstablishment.AdoxioAddresspostalcode },
                        { "licencee", adoxioLicense.AdoxioLicencee.Name },
                        { "effectiveDate", effectiveDateParam },
                        { "expiryDate", expiraryDateParam },
                        { "restrictionsText", termsAndConditions },
                        { "storeHours", storeHours }
                    };
                }
                else if (adoxioLicense.AdoxioLicenceType.AdoxioName == "Marketing")
                {
                    parameters = new Dictionary <string, string>
                    {
                        { "title", "Canabis_License" },
                        { "licenceNumber", adoxioLicense.AdoxioLicencenumber },
                        { "establishmentName", adoxioLicense.AdoxioLicencee.Name },
                        { "establishmentStreet", adoxioLicense.AdoxioLicencee.Address1Line1 },
                        { "establishmentCity", adoxioLicense.AdoxioLicencee.Address1City + ", B.C." },
                        { "establishmentPostalCode", adoxioLicense.AdoxioLicencee.Address1Postalcode },
                        { "licencee", adoxioLicense.AdoxioLicencee.Name },
                        { "effectiveDate", effectiveDateParam },
                        { "expiryDate", expiraryDateParam },
                        { "restrictionsText", termsAndConditions },
                        { "storeHours", storeHours }
                    };
                }
                try
                {
                    var templateName = "cannabis_licence";

                    switch (adoxioLicense.AdoxioLicenceType.AdoxioName)
                    {
                    case "Marketing":
                        templateName = "cannabis_marketer_licence";
                        break;

                    case "Catering Licence":
                        templateName = "catering_licence";
                        break;

                    case "Wine Store Licence":
                        templateName = "wine_store_licence";
                        break;
                    }

                    byte[] data = await _pdfClient.GetPdf(parameters, templateName);

                    return(File(data, "application/pdf", $"{adoxioLicense.AdoxioLicencenumber}.pdf"));
                }
                catch (Exception e)
                {
                    _logger.LogError("Error returning PDF response");
                    _logger.LogError(e.Message);

                    return(new NotFoundResult());
                }
            }
            else
            {
                return(new NotFoundResult());
            }
        }
Beispiel #4
0
        public async Task <IActionResult> GetLicencePDF(string licenceId)
        {
            var expand = new List <string> {
                "adoxio_Licencee",
                "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence",
                "adoxio_adoxio_licences_adoxio_application_AssignedLicence",
                "adoxio_establishment"
            };

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

            if (adoxioLicense == null)
            {
                throw new Exception("Error getting license.");
            }

            if (CurrentUserHasAccessToLicenseOwnedBy(adoxioLicense.AdoxioLicencee.Accountid))
            {
                var effectiveDateParam = "";
                if (adoxioLicense.AdoxioEffectivedate.HasValue)
                {
                    DateTime effectiveDate = adoxioLicense.AdoxioEffectivedate.Value.DateTime;
                    effectiveDateParam = effectiveDate.ToString("dd/MM/yyyy");
                }

                var expiraryDateParam = "";
                if (adoxioLicense.AdoxioExpirydate.HasValue)
                {
                    DateTime expiryDate = adoxioLicense.AdoxioExpirydate.Value.DateTime;
                    expiraryDateParam = expiryDate.ToString("dd/MM/yyyy");
                }

                var termsAndConditions = "";
                foreach (var item in adoxioLicense.AdoxioAdoxioLicencesAdoxioApplicationtermsconditionslimitationLicence)
                {
                    termsAndConditions += $"<li>{item.AdoxioTermsandconditions}</li>";
                }

                var application = adoxioLicense?.AdoxioAdoxioLicencesAdoxioApplicationAssignedLicence?.FirstOrDefault();
                var storeHours  = $@"
                <tr>
                    <td>Open</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                    <td>9:00 am</td>
                </tr>                
                <tr>
                    <td>Close</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                    <td>11:00 pm</td>
                </tr>";
                if (application.AdoxioServicehoursstandardhours != true)
                {
                    storeHours = $@"
                <tr>
                    <td>Open</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursmondayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourstuesdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourswednesdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursthursdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursfridayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssaturdayopen)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssundayopen)}</td>
                </tr>                
                <tr>
                    <td>Close</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursmondayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourstuesdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourswednesdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursthursdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehoursfridayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssaturdayclose)}</td>
                    <td>{ConvertOpenHoursToString(application?.AdoxioServicehourssundayclose)}</td>
                </tr>";
                }

                var parameters = new Dictionary <string, string>
                {
                    { "title", "Canabis_License" },
                    { "licenceNumber", adoxioLicense.AdoxioLicencenumber },
                    { "establishmentName", adoxioLicense.AdoxioEstablishment.AdoxioName },
                    { "establishmentStreet", adoxioLicense.AdoxioEstablishment.AdoxioAddressstreet },
                    { "establishmentCity", adoxioLicense.AdoxioEstablishment.AdoxioAddresscity + ", B.C." },
                    { "establishmentPostalCode", adoxioLicense.AdoxioEstablishment.AdoxioAddresspostalcode },
                    { "licencee", adoxioLicense.AdoxioLicencee.Name },
                    { "effectiveDate", effectiveDateParam },
                    { "expiryDate", expiraryDateParam },
                    { "restrictionsText", termsAndConditions },
                    { "storeHours", storeHours }
                };

                try
                {
                    byte[] data = await _pdfClient.GetPdf(parameters, "cannabis_licence");

                    return(File(data, "application/pdf"));
                }
                catch
                {
                    string basePath = string.IsNullOrEmpty(Configuration["BASE_PATH"]) ? "" : Configuration["BASE_PATH"];
                    basePath += "/dashboard-lite";
                    return(Redirect(basePath));
                }
            }
            else
            {
                return(new NotFoundResult());
            }
        }
        public async Task <IActionResult> GetAuthorizationPdf(string eventId)
        {
            MicrosoftDynamicsCRMadoxioEvent licenceEvent;
            LicenceEvent licenceEventVM;
            MicrosoftDynamicsCRMadoxioLicences licence;
            MicrosoftDynamicsCRMaccount        account;
            string inspectorName;
            string inspectorEmail;
            string inspectorPhone;

            try
            {
                licenceEvent   = _dynamicsClient.Events.GetByKey(eventId);
                licenceEventVM = licenceEvent.ToViewModel(_dynamicsClient);
                licence        = _dynamicsClient.Licenceses.GetByKey(licenceEventVM.LicenceId);
                account        = _dynamicsClient.Accounts.GetByKey(licence._adoxioLicenceeValue);
            }
            catch (HttpOperationException)
            {
                return(new NotFoundResult());
            }

            try
            {
                MicrosoftDynamicsCRMsystemuser inspector = _dynamicsClient.Inspector.Get(eventId);
                inspectorName  = inspector.Fullname;
                inspectorPhone = inspector.Address1Telephone1;
                inspectorEmail = inspector.Internalemailaddress;
            }
            catch (HttpOperationException)
            {
                inspectorName  = "";
                inspectorPhone = "";
                inspectorEmail = "";
            }

            if (!CurrentUserHasAccessToEventOwnedBy(licence._adoxioLicenceeValue))
            {
                return(new NotFoundResult());
            }

            string eventTimings = "";

            foreach (var schedule in licenceEventVM.Schedules)
            {
                eventTimings += $@"<tr class='hide-border'>
                        <td style='width: 50%; text-align: left;'>{schedule.EventStartDateTime?.ToString("MMMM dd, yyyy")} - Event Hours: {schedule.EventStartDateTime?.ToString("h:mm tt")} to {schedule.EventEndDateTime?.ToString("h:mm tt")}</td>
                        <td style='width: 50%; text-align: left;'>Service Hours: {schedule.ServiceStartDateTime?.ToString("h:mm tt")} to {schedule.ServiceEndDateTime?.ToString("h:mm tt")}</td>
                    </tr>";
            }
            Dictionary <string, string> parameters;

            parameters = new Dictionary <string, string>
            {
                { "licensee", account.Name },
                { "licenceNumber", licence.AdoxioLicencenumber },
                { "licenceExpiryDate", licence.AdoxioExpirydate?.ToString("MMMM dd, yyyy") },
                { "licenseePhone", account.Telephone1 },
                { "licenseeEmail", account.Emailaddress1 },
                { "contactName", licenceEventVM.ContactName },
                { "contactPhone", licenceEventVM.ContactPhone },
                { "hostname", licenceEventVM.ClientHostname },
                { "startDate", licenceEventVM.StartDate?.ToString("MMMM dd, yyyy") },
                { "endDate", licenceEventVM.EndDate?.ToString("MMMM dd, yyyy") },
                { "eventTimings", eventTimings },
                { "eventType", EnumExtensions.GetEnumMemberValue(licenceEventVM.EventType) },
                { "eventDescription", licenceEventVM.EventTypeDescription },
                { "foodService", EnumExtensions.GetEnumMemberValue(licenceEventVM.FoodService) },
                { "entertainment", EnumExtensions.GetEnumMemberValue(licenceEventVM.Entertainment) },
                { "attendance", licenceEventVM.MaxAttendance.ToString() },
                { "minors", licenceEventVM.MinorsAttending ?? false ? "Yes" : "No" },
                { "location", licenceEventVM.SpecificLocation.ToString() },
                { "addressLine1", licenceEventVM.Street1 },
                { "addressLine2", licenceEventVM.Street2 },
                { "addressLine3", $"{licenceEventVM.City}, BC {licenceEventVM.PostalCode}" },
                { "inspectorName", inspectorName },
                { "inspectorPhone", inspectorPhone },
                { "inspectorEmail", inspectorEmail },
                { "date", DateTime.Now.ToString("MMMM dd, yyyy") }
            };

            byte[] data;
            try
            {
                data = await _pdfClient.GetPdf(parameters, "event_authorization");

                return(File(data, "application/pdf", $"authorization.pdf"));
            }
            catch (Exception)
            {
                return(new NotFoundResult());
            }
        }
Beispiel #6
0
        public async Task <IActionResult> GetLicencePDF(string workerId)
        {
            var expand = new List <string> {
                "adoxio_ContactId"
            };

            MicrosoftDynamicsCRMadoxioWorker adoxioWorker = _dynamicsClient.Workers.GetByKey(workerId, expand: expand);

            if (adoxioWorker == null)
            {
                _logger.LogError($"Unable to send Worker Qualification Letter for worker {workerId} - unable to get worker record");
                throw new Exception("Error getting worker.");
            }

            if (!CurrentUserHasAccessToContactWorkerApplicationOwnedBy(adoxioWorker?.AdoxioContactId?.Contactid))
            {
                _logger.LogError($"Unable to send Worker Qualification Letter for worker {workerId} - current user does not have access to worker");
                return(NotFound("No access to worker"));
            }

            try
            {
                var dateOfBirthParam = "";
                if (adoxioWorker.AdoxioDateofbirth.HasValue)
                {
                    DateTime dateOfBirth = adoxioWorker.AdoxioDateofbirth.Value.DateTime;
                    dateOfBirthParam = dateOfBirth.ToString("dd/MM/yyyy");
                }

                var effectiveDateParam = "";
                if (adoxioWorker.AdoxioSecuritycompletedon != null)
                {
                    DateTime effectiveDate = adoxioWorker.AdoxioSecuritycompletedon.Value.DateTime;
                    effectiveDateParam = effectiveDate.ToString("dd/MM/yyyy");
                }

                var expiryDateParam = "";
                if (adoxioWorker.AdoxioExpirydate != null)
                {
                    DateTime expiryDate = adoxioWorker.AdoxioExpirydate.Value.DateTime;
                    expiryDateParam = expiryDate.ToString("dd/MM/yyyy");
                }

                var parameters = new Dictionary <string, string>
                {
                    { "title", "Worker_Qualification" },
                    { "currentDate", DateTime.Now.ToLongDateString() },
                    { "firstName", adoxioWorker.AdoxioFirstname },
                    { "middleName", adoxioWorker.AdoxioMiddlename },
                    { "lastName", adoxioWorker.AdoxioLastname },
                    { "dateOfBirth", dateOfBirthParam },
                    { "address", adoxioWorker.AdoxioContactId.Address1Line1 },
                    { "city", adoxioWorker.AdoxioContactId.Address1City },
                    { "province", adoxioWorker.AdoxioContactId.Address1Stateorprovince },
                    { "postalCode", adoxioWorker.AdoxioContactId.Address1Postalcode },
                    { "effectiveDate", effectiveDateParam },
                    { "expiryDate", expiryDateParam },
                    { "border", "{ \"top\": \"40px\", \"right\": \"40px\", \"bottom\": \"0px\", \"left\": \"40px\" }" }
                };

                byte[] data = await _pdfClient.GetPdf(parameters, "worker_qualification_letter");

                _logger.LogInformation($"Sending Worker Qualification Letter for worker {workerId}");
                return(File(data, "application/pdf", "WorkerQualificationLetter.pdf"));
            }
            catch (Exception e)
            {
                string basePath = string.IsNullOrEmpty(_configuration["BASE_PATH"]) ? "" : _configuration["BASE_PATH"];
                basePath += "/worker-qualification/dashboard";
                _logger.LogError(e, $"Unable to send Worker Qualification Letter for worker {workerId}");
                return(Redirect(basePath));
            }
        }