public ServiceResponse <bool> SaveAsync(AccreditationOutcomeItem accreditationOutcomeItem)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                var accreditationOutcomeFacade = this.Container.GetInstance <AccreditationOutcomeFacade>();

                accreditationOutcomeFacade.Save(accreditationOutcomeItem, Email, AccessToken);
                base.LogMessage("SaveAsync", DateTime.Now - startTime);

                return(new ServiceResponse <bool>
                {
                    Item = true,
                    Message = "Accreditation Outcome updated successfully"
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <bool>
                {
                    HasError = true,
                    Message = ex.Message
                });
            }
        }
Beispiel #2
0
        public void Save(AccreditationOutcomeItem accreditationOutcomeItem, string email)
        {
            LogMessage("Save (AccreditationOutcomeManager)");

            AccreditationOutcome accreditationOutcome = new AccreditationOutcome();

            accreditationOutcome.OrganizationId       = accreditationOutcomeItem.OrganizationId;
            accreditationOutcome.ApplicationId        = accreditationOutcomeItem.ApplicationId;
            accreditationOutcome.OutcomeStatusId      = accreditationOutcomeItem.OutcomeStatusId;
            accreditationOutcome.ReportReviewStatusId = accreditationOutcomeItem.ReportReviewStatusId;
            accreditationOutcome.CommitteeDate        = Convert.ToDateTime(accreditationOutcomeItem.CommitteeDate);
            accreditationOutcome.SendEmail            = accreditationOutcome.SendEmail;

            accreditationOutcome.CreatedBy   = email;
            accreditationOutcome.CreatedDate = DateTime.Now;

            base.Repository.Add(accreditationOutcome);
        }
        private void SendAccrediationEmail(AccreditationOutcomeItem accreditationOutcomeItem, Organization org, Application application, string accessToken)
        {
            var applicationSettingManager = this.container.GetInstance <ApplicationSettingManager>();
            var trueVaultManager          = this.container.GetInstance <TrueVaultManager>();
            var reportingFacade           = this.container.GetInstance <ReportingFacade>();

            if (!string.IsNullOrWhiteSpace(accreditationOutcomeItem.EmailContent))
            {
                Log.Info($"Starting to send email with subject: {accreditationOutcomeItem.Subject}");

                var factEmail = applicationSettingManager.GetByName(Constants.ApplicationSettings.AutoCcEmailAddress);

                Stream accReportStream = null;

                List <String> cc = new List <string>();

                if (!string.IsNullOrEmpty(accreditationOutcomeItem.Cc))
                {
                    cc = accreditationOutcomeItem.Cc.Split(new char[] { ',', ';' }).ToList();
                }

                var emailMessage = EmailHelper.BuildMessage(accreditationOutcomeItem.To.Split(new char[] { ',', ';' }).ToList(), cc, accreditationOutcomeItem.Subject, accreditationOutcomeItem.EmailContent);
                var streams      = new List <Stream>();

                foreach (var doc in accreditationOutcomeItem.AttachedDocuments)
                {
                    var stream = trueVaultManager.DownloadFile(accessToken, org.DocumentLibraryVaultId, doc.RequestValues);

                    streams.Add(stream);
                    emailMessage.Message.Attachments.Add(new Attachment(stream, doc.Name));
                }

                if (accreditationOutcomeItem.IncludeAccreditationReport)
                {
                    var documentManager = this.container.GetInstance <DocumentManager>();

                    var cycleNumber = 1;

                    if (org.OrganizationAccreditationCycles != null &&
                        org.OrganizationAccreditationCycles.Count > 0)
                    {
                        cycleNumber = org.OrganizationAccreditationCycles.Max(c => c.Number);
                    }

                    var fileName =
                        $"Accreditation Rpt - {DateTime.Now.Month}_{DateTime.Now.Day}_{DateTime.Now.Year} - {org.Name.Replace(" ", "")}.pdf";

                    var document = reportingFacade.CopyReport(Constants.Reports.AccreditationReport, org.DocumentLibraryVaultId,
                                                              application.ComplianceApplicationId.GetValueOrDefault(), org.Name, cycleNumber, false, fileName, fileName);

                    accReportStream = trueVaultManager.DownloadFile(accessToken, org.DocumentLibraryVaultId, document.RequestValues);

                    emailMessage.Message.Attachments.Add(new Attachment(accReportStream, fileName));
                }

                emailMessage.SmtpClient.Send(emailMessage.Message);

                streams.ForEach(x => x.Close());
                accReportStream?.Dispose();

                Log.Info($"Finished sending email with subject: {accreditationOutcomeItem.Subject}");
            }
        }
        public void Save(AccreditationOutcomeItem accreditationOutcomeItem, string currentUser, string accessToken)
        {
            var orgManager = this.container.GetInstance <OrganizationManager>();
            var inspectionScheduleFacade    = this.container.GetInstance <InspectionScheduleFacade>();
            var accreditationOutcomeManager = this.container.GetInstance <AccreditationOutcomeManager>();
            var applicationManager          = this.container.GetInstance <ApplicationManager>();
            var applicationStatusManager    = this.container.GetInstance <ApplicationStatusManager>();
            var inspectionScheduleManager   = this.container.GetInstance <InspectionScheduleManager>();
            var accreditationStatusManager  = this.container.GetInstance <AccreditationStatusManager>();

            var org = orgManager.GetById(accreditationOutcomeItem.OrganizationId);

            accreditationOutcomeItem.OrganizationName = org.Name;
            var application       = applicationManager.GetById(accreditationOutcomeItem.ApplicationId);
            var completeStatus    = applicationStatusManager.GetByName(Constants.ApplicationStatus.Complete);
            var cancelledStatus   = applicationStatusManager.GetByName(Constants.ApplicationStatus.Cancelled);
            var appResponseStatus = applicationStatusManager.GetByName(Constants.ApplicationStatus.ApplicantResponse);

            var accreditationStatuses = accreditationStatusManager.GetAll();

            var accreditedStatus =
                accreditationStatuses.SingleOrDefault(x => x.Name == Constants.AccreditationStatuses.Accredited);

            var suspendedStatus =
                accreditationStatuses.SingleOrDefault(
                    x => x.Name == Constants.AccreditationStatuses.Suspended);

            var withdrawnStatus =
                accreditationStatuses.SingleOrDefault(x => x.Name == Constants.AccreditationStatuses.Withdrawn);

            if (accreditedStatus == null || suspendedStatus == null || withdrawnStatus == null)
            {
                throw new Exception("Cannot Find the Accredition Statuses");
            }

            accreditationOutcomeItem.SendEmail = !string.IsNullOrWhiteSpace(accreditationOutcomeItem.EmailContent);

            accreditationOutcomeManager.Save(accreditationOutcomeItem, currentUser);

            var apps =
                applicationManager.GetByComplianceApplicationId(application.ComplianceApplicationId.GetValueOrDefault());

            foreach (var app in apps)
            {
                if (accreditationOutcomeItem.OutcomeStatusId == (int)Constants.OutcomeStatuses.Level1) //Level1 = Complete
                {
                    app.ApplicationStatusId = completeStatus.Id;
                }
                else if (accreditationOutcomeItem.OutcomeStatusId == (int)Constants.OutcomeStatuses.Level6) //Level6 = Cancelled
                {
                    app.ApplicationStatusId = cancelledStatus.Id;
                }
                else
                {
                    app.ApplicationStatusId = appResponseStatus.Id;
                    app.RFIDueDate          = accreditationOutcomeItem.DueDate.GetValueOrDefault();
                }

                app.UpdatedBy   = currentUser;
                app.UpdatedDate = DateTime.Now;
                applicationManager.Save(app);
            }



            switch (accreditationOutcomeItem.OutcomeStatusId)
            {
            case (int)Constants.OutcomeStatuses.Level1:
                if (accreditationOutcomeItem.ReportReviewStatusName != Constants.ReportReviewStatus.AddOn)
                {
                    orgManager.ChangeOrgToAccredited(org, accreditedStatus, currentUser);
                }

                var reportingFacade = this.container.GetInstance <ReportingFacade>();


                var fileName =
                    $"Outcomes Rpt -{org.Name}_{application.CycleNumber}_{DateTime.Now.Month}_{DateTime.Now.Day}_{DateTime.Now.Year} - {org.Name.Replace(" ", "")}.pdf";

                reportingFacade.CopyReport(Constants.Reports.OutcomesData, org.DocumentLibraryVaultId,
                                           application.ComplianceApplicationId.GetValueOrDefault(), org.Name, 0, true, fileName, fileName);

                break;

            case (int)Constants.OutcomeStatuses.Level4:
            case (int)Constants.OutcomeStatuses.Level5:
                var inspectionSchedule =
                    inspectionScheduleManager.GetInspectionScheduleByAppIdOrganizationID(
                        accreditationOutcomeItem.OrganizationId, accreditationOutcomeItem.ApplicationId, false);

                if (inspectionSchedule != null && inspectionSchedule.Count > 0)
                {
                    inspectionScheduleFacade.ArchiveScheduleAsync(inspectionSchedule[0].Id);
                }
                break;

            case (int)Constants.OutcomeStatuses.Level6:
                org.AccreditationStatusId = org.AccreditationStatusId == accreditedStatus.Id ? suspendedStatus.Id : withdrawnStatus.Id;
                break;
            }

            org.UseTwoYearCycle = accreditationOutcomeItem.UseTwoYearCycle;
            org.UpdatedBy       = currentUser;
            org.UpdatedDate     = DateTime.Now;
            orgManager.Save(org);

            this.SendAccrediationEmail(accreditationOutcomeItem, org, application, accessToken);
        }