Esempio n. 1
0
        public async Task <ActionResult <Pdf> > GetPdf(Guid id)
        {
            var pdf = await _pdfService.GetPdf(id);

            if (pdf == null)
            {
                return(NotFound());
            }

            return(pdf);
        }
        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");

                // Save copy of generated licence PDF for auditing/logging purposes
                try
                {
                    var hash = await _pdfClient.GetPdfHash(parameters, "worker_qualification_letter");

                    var entityName = "worker";
                    var entityId   = adoxioWorker.AdoxioWorkerid;
                    var folderName = await _dynamicsClient.GetFolderName(entityName, entityId).ConfigureAwait(true);

                    var documentType = "WorkerQualification";
                    _fileManagerClient.UploadPdfIfChanged(_logger, entityName, entityId, folderName, documentType, data, hash);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error uploading PDF");
                }

                _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));
            }
        }
        public async Task <IActionResult> GetAuthorizationPdf(string eventId)
        {
            MicrosoftDynamicsCRMadoxioEvent licenceEvent;
            LicenceEvent licenceEventVM;
            MicrosoftDynamicsCRMadoxioLicences licence;
            MicrosoftDynamicsCRMaccount        account;

            try
            {
                licenceEvent   = _dynamicsClient.Events.GetByKey(eventId);
                licenceEventVM = licenceEvent.ToViewModel(_dynamicsClient);
                licence        = _dynamicsClient.Licenceses.GetByKey(
                    licenceEventVM.LicenceId,
                    expand: new List <string> {
                    "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence"
                });
                account = _dynamicsClient.Accounts.GetByKey(licence._adoxioLicenceeValue);
            }
            catch (HttpOperationException)
            {
                return(new NotFoundResult());
            }

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

            string       eventTimings = "";
            TimeZoneInfo hwZone;

            try
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("America/Vancouver");
            }
            catch (System.TimeZoneNotFoundException)
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            }

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

            var termsAndConditions = "";

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

            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 },
                { "contactEmail", licenceEventVM.ContactEmail },
                { "contactPhone", licenceEventVM.ContactPhone },
                { "hostname", licenceEventVM.ClientHostname },
                { "startDate", licenceEventVM.StartDate?.ToString("MMMM dd, yyyy") },
                { "endDate", licenceEventVM.EndDate?.ToString("MMMM dd, yyyy") },
                { "eventTimings", eventTimings },
                { "eventType", licenceEventVM.EventType.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.EventType) : "" },
                { "eventDescription", licenceEventVM.EventTypeDescription },
                { "foodService", licenceEventVM.FoodService.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.FoodService) : "" },
                { "entertainment", licenceEventVM.Entertainment.HasValue ? 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", licenceEvent.AdoxioEventinspectorname },
                { "inspectorPhone", licenceEvent.AdoxioEventinspectorphone },
                { "inspectorEmail", licenceEvent.AdoxioEventinspectoremail },
                { "date", DateTime.Now.ToString("MMMM dd, yyyy") },
                { "marketName", licenceEventVM.MarketName },
                { "marketDuration", licenceEventVM.MarketDuration.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.MarketDuration) : "" },
                { "restrictionsText", termsAndConditions }
            };

            byte[] data;
            try
            {
                string pdfType = null;
                if (licenceEventVM.EventCategory == EventCategory.Market)
                {
                    pdfType = "market_event_authorization";
                }
                else if (licenceEventVM.EventCategory == EventCategory.Catering)
                {
                    pdfType = "catering_event_authorization";
                }
                if (pdfType != null)
                {
                    data = await _pdfClient.GetPdf(parameters, pdfType);

                    return(File(data, "application/pdf", $"authorization.pdf"));
                }
                return(new NotFoundResult());
            }
            catch (Exception)
            {
                return(new NotFoundResult());
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> GetAuthorizationPdf(string eventId)
        {
            MicrosoftDynamicsCRMadoxioEvent licenceEvent;
            LicenceEvent licenceEventVM;
            MicrosoftDynamicsCRMadoxioLicences licence;
            MicrosoftDynamicsCRMaccount        account;
            Dictionary <string, string>        serviceAreas;

            try
            {
                licenceEvent   = _dynamicsClient.Events.GetByKey(eventId);
                licenceEventVM = licenceEvent.ToViewModel(_dynamicsClient);
                licence        = _dynamicsClient.Licenceses.GetByKey(
                    licenceEventVM.LicenceId,
                    expand: new List <string> {
                    "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence"
                });
                account = _dynamicsClient.Accounts.GetByKey(licence._adoxioLicenceeValue);
                var areas = LicenseExtensions.GetServiceAreas(licence.AdoxioLicencesid, _dynamicsClient);
                // Create lookup dictionary with service areas to speed up lookup times (vs an array)
                serviceAreas = areas.ToDictionary(x => x.Id, x => x.AreaLocation);
            }
            catch (HttpOperationException)
            {
                return(new NotFoundResult());
            }

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

            string       eventTimings = "";
            TimeZoneInfo hwZone;

            try
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("America/Vancouver");
            }
            catch (TimeZoneNotFoundException)
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            }

            foreach (var schedule in licenceEventVM.Schedules)
            {
                // Event times are stored in UTC but we want the printed PDF to reflect times and dates in Pacific Standard Time (PST)
                DateTime?pstStart       = schedule.EventStartDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.EventStartDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstEnd         = schedule.EventEndDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.EventEndDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstLiquorStart = schedule.ServiceStartDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.ServiceStartDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstLiquorEnd   = schedule.ServiceEndDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.ServiceEndDateTime.Value.DateTime, hwZone) : (DateTime?)null;

                string eventDate       = pstStart.HasValue ? pstStart.Value.ToString("MMMM dd, yyyy") : "";
                string startTime       = pstStart.HasValue ? pstStart.Value.ToString("h:mm tt") : "";
                string endTime         = pstEnd.HasValue ? pstEnd.Value.ToString("h:mm tt") : "";
                string liquorStartTime = pstLiquorStart.HasValue ? pstLiquorStart.Value.ToString("h:mm tt") : "";
                string liquorEndTime   = pstLiquorEnd.HasValue ? pstLiquorEnd.Value.ToString("h:mm tt") : "";
                eventTimings += $@"<tr class='hide-border'>
                        <td style='width: 50%; text-align: left;'>{eventDate} - Event Hours: {startTime} to {endTime}</td>
                        <td style='width: 50%; text-align: left;'>Service Hours: {liquorStartTime} to {liquorEndTime}</td>
                    </tr>";
            }

            var eventLocations = "";

            if (licenceEventVM.EventLocations.Count > 0)
            {
                eventLocations += $@"<table style='width: 100%'>
                    <thead>
                        <tr>
                            <th>Location ID</th>
                            <th>Location Name</th>
                            <th>Attendance</th>
                        </tr>
                    </thead>";
                foreach (var location in licenceEventVM.EventLocations)
                {
                    string area = serviceAreas.GetValueOrDefault(location.ServiceAreaId, "");
                    eventLocations += $@"<tr class='hide-border'>
                        <td style='width: 30%; text-align: left;'>{area}</td>
                        <td style='width: 50%; text-align: left;'>{location.Name ?? ""}</td>
                        <td style='width: 20%; text-align: left;'>{location.Attendance ?? 0}</td>
                    </tr>";
                }
                eventLocations += "</table>";
            }

            var termsAndConditions = "";

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

            var 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 },
                { "contactEmail", licenceEventVM.ContactEmail },
                { "contactPhone", licenceEventVM.ContactPhone },
                { "hostname", licenceEventVM.ClientHostname },
                { "startDate", licenceEventVM.StartDate?.ToString("MMMM dd, yyyy") },
                { "endDate", licenceEventVM.EndDate?.ToString("MMMM dd, yyyy") },
                { "eventTimings", eventTimings },
                { "eventNumber", licenceEventVM.EventNumber },
                { "eventType", licenceEventVM.EventType.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.EventType) : "" },
                { "eventDescription", licenceEventVM.EventTypeDescription },
                { "foodService", licenceEventVM.FoodService.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.FoodService) : "" },
                { "entertainment", licenceEventVM.Entertainment.HasValue ? 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", licenceEvent.AdoxioEventinspectorname },
                { "inspectorPhone", licenceEvent.AdoxioEventinspectorphone },
                { "inspectorEmail", licenceEvent.AdoxioEventinspectoremail },
                { "date", DateTime.Now.ToString("MMMM dd, yyyy") },
                { "marketName", licenceEventVM.MarketName },
                { "marketDuration", licenceEventVM.MarketDuration.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.MarketDuration) : "" },
                { "restrictionsText", termsAndConditions },
                // TUA-specific fields
                { "tuaEventType", licenceEventVM.TuaEventType.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.TuaEventType) : "" },
                { "isClosedToPublic", licenceEventVM.IsClosedToPublic ?? false ? "Yes" : "No" },
                { "isWedding", licenceEventVM.IsWedding ?? false ? "1" : null },
                { "isNetworkingParty", licenceEventVM.IsNetworkingParty ?? false ? "1" : null },
                { "isConcert", licenceEventVM.IsConcert ?? false ? "1" : null },
                { "isNoneOfTheAbove", licenceEventVM.IsNoneOfTheAbove ?? false ? "1" : null },
                { "isBanquet", licenceEventVM.IsBanquet ?? false ? "1" : "" },
                { "isAmplifiedSound", licenceEventVM.IsAmplifiedSound ?? false ? "1" : null },
                { "isDancing", licenceEventVM.IsDancing ?? false ? "1" : null },
                { "isReception", licenceEventVM.IsReception ?? false ? "1" : null },
                { "isLiveEntertainment", licenceEventVM.IsLiveEntertainment ?? false ? "1" : null },
                { "isGambling", licenceEventVM.IsGambling ?? false ? "1" : null },
                { "eventLocations", eventLocations },
            };

            byte[] data;
            try
            {
                string pdfType = null;
                if (licenceEventVM.EventCategory == EventCategory.Market)
                {
                    pdfType = "market_event_authorization";
                }
                else if (licenceEventVM.EventCategory == EventCategory.Catering)
                {
                    pdfType = "catering_event_authorization";
                }
                else if (licenceEventVM.EventCategory == EventCategory.TemporaryUseArea)
                {
                    pdfType = "tua_event_authorization";
                }
                if (pdfType != null)
                {
                    data = await _pdfClient.GetPdf(parameters, pdfType).ConfigureAwait(true);

                    // Save copy of generated licence PDF for auditing/logging purposes
                    try
                    {
                        var hash = await _pdfClient.GetPdfHash(parameters, pdfType);

                        var entityName = "event";
                        var entityId   = eventId;
                        var folderName = await _dynamicsClient.GetFolderName(entityName, entityId).ConfigureAwait(true);

                        var documentType = "EventAuthorization";
                        _fileManagerClient.UploadPdfIfChanged(_logger, entityName, entityId, folderName, documentType, data, hash);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Error uploading PDF");
                    }

                    return(File(data, "application/pdf", "authorization.pdf"));
                }
                return(new NotFoundResult());
            }
            catch (Exception)
            {
                return(new NotFoundResult());
            }
        }