public void Approve([FromBody] Models.Presentation.ReportSignatureModel signatureInfo)
        {
            string userName = System.Web.HttpContext.Current.User.Identity.Name.Substring(5).ToLower();

            if (userName.ToLower() != signatureInfo.userName.ToLower())
            {
                throw new Exception("Current user information is not synchronized.  Cannot approve report.");
            }

            SessionController session = new SessionController();

            bool userVerified = session.VerifyPassword(userName, signatureInfo.signature);

            session.Dispose();

            if (userVerified)
            {
                Models.Medical medicalAssessment = this._db.Medicals.Where(m => m.incidentMedicalId == signatureInfo.incidentMedicalId).SingleOrDefault();

                if (medicalAssessment != null)
                {
                    // SET STATUS OF ASSESSMENT TO CLOSED
                    medicalAssessment.statusId = 6;
                    this._db.Medicals.Attach(medicalAssessment);
                    this._db.Entry(medicalAssessment).State = System.Data.Entity.EntityState.Modified;



                    // CREATE SIGNATURE RECORD
                    Models.ReportSign medicalSignature = new Models.ReportSign();

                    medicalSignature.incidentId        = signatureInfo.incidentId;
                    medicalSignature.incidentMedicalId = signatureInfo.incidentMedicalId;
                    medicalSignature.reportSigType     = "M";
                    medicalSignature.reportSigUserId   = signatureInfo.currentUser;
                    medicalSignature.staffName         = signatureInfo.staffName;
                    medicalSignature.staffTitle        = signatureInfo.staffTitle;
                    medicalSignature.approvalStatusId  = 3;
                    medicalSignature.reportSigStamp    = DateTime.Now;
                    medicalSignature.reportSigStation  = signatureInfo.stationName;

                    this._db.ReportSigns.Add(medicalSignature);
                    this._db.SaveChanges();
                }
                else
                {
                    throw new Exception("Medical Assessment could not be found.");
                } // if (medicalAssessment != null)
            }
            else
            {
                throw new Exception("Unable to validate signature.  Please use your current CFS account password to sign.");
            } // if (userVerified)
        }
        public void SupervisorFinalApprove([FromBody] Models.Presentation.ReportSignatureModel signatureInfo)
        {
            Models.IncidentReport report = this._db.IncidentReports.Where(r => r.incidentId == signatureInfo.incidentId).SingleOrDefault();
            string logDetails            = string.Empty;


            if (report != null)
            {
                string userName = System.Web.HttpContext.Current.User.Identity.Name.Substring(5).ToLower();
                if (userName.ToLower() != signatureInfo.userName.ToLower())
                {
                    throw new Exception("Current user information is not synchronized.  Cannot approve report.");
                }

                SessionController session = new SessionController();

                bool userVerified = session.VerifyPassword(userName, signatureInfo.signature);
                session.Dispose();

                if (userVerified)
                {
                    // GET SUPERVISOR SIGNATURE RECORD
                    Models.ReportSign supervisorSignature = this._db.ReportSigns.Where(
                        s => s.incidentId == signatureInfo.incidentId &&
                        s.reportSigType == "S" &&
                        s.reportSigUserId == signatureInfo.currentUser).SingleOrDefault();

                    if (supervisorSignature == null)
                    {
                        throw new Exception("Could not find signature record.  Cannot approve report.");
                    }
                    else
                    {
                        supervisorSignature.approvalStatusId = signatureInfo.approvalStatusId;
                        supervisorSignature.reportSigStamp   = DateTime.Now;
                        supervisorSignature.reportSigStation = signatureInfo.stationName;
                        supervisorSignature.approvalComments = signatureInfo.approvalComments;

                        this._db.ReportSigns.Attach(supervisorSignature);
                        this._db.Entry(supervisorSignature).State = System.Data.Entity.EntityState.Modified;



                        if (signatureInfo.approvalStatusId == 3) // SUPERVISOR APPROVED
                        {
                            // SUPERVISOR APPROVES, REPORT SENT TO ADMINS FOR REVIEW
                            Models.ReportSign adminSignature = new Models.ReportSign();

                            adminSignature.incidentId        = signatureInfo.incidentId;
                            adminSignature.incidentMedicalId = 0;
                            adminSignature.reportSigType     = "A";
                            adminSignature.reportSigUserId   = 0;
                            adminSignature.staffName         = "Administrator";
                            adminSignature.staffTitle        = "Administrator";
                            adminSignature.approvalStatusId  = 1;

                            this._db.ReportSigns.Add(adminSignature);

                            // EMAIL ADMINS!!!! (INCLUDE ADMINS?)

                            logDetails = "Supervisor approved report.";
                        }
                        else
                        {
                            // NOTIFY EMPLOYEE REPORT REJECTED


                            logDetails = "Supervisor rejected report. Comments: " + signatureInfo.approvalComments;
                        } // if (signatureInfo.approvalStatusId == 3)


                        // UPDATE REPORT STATUS

                        report.statusId       = signatureInfo.statusId;
                        report.currentUser    = signatureInfo.currentUser;
                        report.lastModified   = DateTime.Now;
                        report.lastModifiedBy = signatureInfo.currentUser;

                        this._db.IncidentReports.Attach(report);
                        this._db.Entry(report).State = System.Data.Entity.EntityState.Modified;


                        // WRITE CHANGES TO LOG

                        Models.ReportLog log = new Models.ReportLog();

                        log.incidentId  = signatureInfo.incidentId;
                        log.userId      = signatureInfo.currentUser;
                        log.userStation = signatureInfo.stationName;
                        log.logDateTime = DateTime.Now;
                        log.logDetails  = logDetails;

                        this._db.ReportLogs.Add(log);



                        // IF JUSTICE CENTER CALLED, NOTIFY CORPORATE COMPLIANCE


                        // notifyPartyId = 8 (Justice Center)
                        bool jcCalled = this._db.Notifications.Where(n => n.incidentId == signatureInfo.incidentId && n.notifyPartyId == 8).Any();

                        if (jcCalled)
                        {
                            Models.Notification ccNotification = new Models.Notification();

                            ccNotification.incidentId        = signatureInfo.incidentId;
                            ccNotification.notifyPartyId     = 37; // Corporate Compliance
                            ccNotification.notifyDateTime    = DateTime.Now;
                            ccNotification.notifyContact     = "CFS Corporate Compliance";
                            ccNotification.notifyMethod      = "E-Mail";
                            ccNotification.notifyStaffId     = 0;
                            ccNotification.isAcknowledged    = 1;
                            ccNotification.acknowledgeUserId = 0;

                            this._db.Notifications.Add(ccNotification);

                            MailController mailer = new MailController();

                            List <string> sendTos = new List <string>();
                            sendTos.Add("*****@*****.**");

                            StringBuilder msg = new StringBuilder();
                            msg.Append("<h1>Incident Report Notification</h1>");
                            msg.Append("<p>An incident report has been created for client " + report.clientName + " by " + report.staffName);
                            msg.Append(", and the Justice Center was called.</p>");

                            mailer.SendMail(sendTos, "*****@*****.**", "Incident Reports: Justice Center Called", System.Net.Mail.MailPriority.Normal, msg);
                        }



                        this._db.SaveChanges();
                    }  // if (supervisorSignature == null)
                }
                else
                {
                    throw new Exception("Unable to validate signature.  Please use your current CFS account password to sign.");
                }  // if (userVerified)
            }
        }
        public void FinalApprove([FromBody] Models.Presentation.ReportSignatureModel signatureInfo)
        {
            Models.IncidentReport report = this._db.IncidentReports.Where(r => r.incidentId == signatureInfo.incidentId).SingleOrDefault();

            if (report != null)
            {
                string userName = System.Web.HttpContext.Current.User.Identity.Name.Substring(5).ToLower();
                if (userName.ToLower() != signatureInfo.userName.ToLower())
                {
                    throw new Exception("Current user information is not synchronized.  Cannot approve report.");
                }

                SessionController session = new SessionController();

                bool userVerified = session.VerifyPassword(userName, signatureInfo.signature);
                session.Dispose();

                if (userVerified)
                {
                    Models.ReportSign staffSignature = new Models.ReportSign();

                    staffSignature.incidentId        = signatureInfo.incidentId;
                    staffSignature.incidentMedicalId = 0;
                    staffSignature.reportSigType     = "E";
                    staffSignature.reportSigUserId   = signatureInfo.currentUser;
                    staffSignature.staffName         = signatureInfo.staffName;
                    staffSignature.staffTitle        = signatureInfo.staffTitle;
                    staffSignature.approvalStatusId  = 3;
                    staffSignature.reportSigStamp    = DateTime.Now;
                    staffSignature.reportSigStation  = signatureInfo.stationName;

                    this._db.ReportSigns.Add(staffSignature);



                    StaffController staffs     = new StaffController();
                    Models.User     supervisor = staffs.GetStaffSupervisor(signatureInfo.currentUser);
                    staffs.Dispose();


                    Models.ReportSign supervisorSignature = new Models.ReportSign();

                    supervisorSignature.incidentId        = signatureInfo.incidentId;
                    supervisorSignature.incidentMedicalId = 0;
                    supervisorSignature.reportSigType     = "S";
                    supervisorSignature.reportSigUserId   = supervisor.userId;
                    supervisorSignature.staffName         = supervisor.firstName + " " + supervisor.lastName;
                    supervisorSignature.staffTitle        = supervisor.jobTitle;
                    supervisorSignature.approvalStatusId  = 1;

                    this._db.ReportSigns.Add(supervisorSignature);



                    // WRITE CHANGES TO LOG

                    Models.ReportLog log = new Models.ReportLog();

                    log.incidentId  = signatureInfo.incidentId;
                    log.userId      = signatureInfo.currentUser;
                    log.userStation = signatureInfo.stationName;
                    log.logDateTime = DateTime.Now;
                    log.logDetails  = "Report signed by staff.";

                    this._db.ReportLogs.Add(log);



                    // EMAIL SUPERVISOR!!!! (INCLUDE ADMINS?)


                    MailController mailer      = new MailController();
                    StringBuilder  messageBody = new StringBuilder();
                    messageBody.Append("<p>A new incident report for <b>" + report.clientName + "</b> has been posted by " + report.staffName + ".</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidents/report/residential/" + report.incidentId.ToString() + "\">Click here to view the report.</a></p>");

                    mailer.SendMail(
                        new List <string>()
                    {
                        supervisor.eMail, "*****@*****.**"
                    },
                        "*****@*****.**",
                        "Incident Report Posted",
                        System.Net.Mail.MailPriority.High,
                        messageBody
                        );

                    mailer.Dispose();



                    report.statusId       = signatureInfo.statusId;
                    report.currentUser    = signatureInfo.currentUser;
                    report.lastModified   = DateTime.Now;
                    report.lastModifiedBy = signatureInfo.currentUser;

                    this._db.IncidentReports.Attach(report);
                    this._db.Entry(report).State = System.Data.Entity.EntityState.Modified;



                    this._db.SaveChanges();
                }
                else
                {
                    throw new Exception("Unable to validate signature.  Please use your current CFS account password to sign.");
                }
            }
        }
예제 #4
0
        public void CreateReportSignatures([FromBody] Models.Presentation.ReportIdsForSignature value)
        {
            try
            {
                var report = this._db.IncidentReports.Where(r => r.incidentId == value.reportId).SingleOrDefault();

                if (report != null)
                {
                    report.statusId = 5;
                    this._db.SaveChanges();
                }
                else
                {
                    throw new Exception("Report not found!");
                }


                Models.CfsMasterDbEntities _userDb = new Models.CfsMasterDbEntities();
                List <string> sendTos = new List <string>();



                var userDetails = _userDb.Users.Where(u => u.userId == value.userId).SingleOrDefault();

                if (userDetails == null)
                {
                    var errorMessage = "Current user not found.";
                    Helpers.Mailer.SendExceptionDetail("post:/api/signatures/create", errorMessage, string.Empty, string.Empty, value);
                    throw new Exception(errorMessage);
                }
                else
                {
                    Models.ReportSign employeeSignature = new Models.ReportSign();

                    employeeSignature.incidentId        = value.reportId;
                    employeeSignature.reportSigUserId   = value.userId;
                    employeeSignature.staffName         = string.Format("{0} {1}", userDetails.firstName, userDetails.lastName);
                    employeeSignature.staffTitle        = userDetails.jobTitle;
                    employeeSignature.reportSigType     = "A";
                    employeeSignature.approvalStatusId  = 3;
                    employeeSignature.incidentMedicalId = 0;
                    employeeSignature.reportSigCreated  = DateTime.Now;
                    employeeSignature.reportSigStamp    = DateTime.Now;
                    employeeSignature.reportSigStation  = value.stationName;


                    this._db.ReportSigns.Add(employeeSignature);
                    this._db.SaveChanges();

                    sendTos.Add(userDetails.eMail);


                    int costCenterId = userDetails.costCenterId;


                    var programDetails = this._db.IncidentPrograms.Where(p => p.incidentProgramId == report.programId).SingleOrDefault();
                    var managerId      = programDetails.managerId;
                    var directorId     = programDetails.directorId;

                    var costCenter = _userDb.CostCenters.Where(c => c.costCenterId == userDetails.costCenterId).SingleOrDefault();
                    var supervisor = _userDb.Users.Where(u => u.userId == userDetails.supervisorId).SingleOrDefault();
                    //var manager = _userDb.Users.Where(u => u.userId == costCenter.directorId).SingleOrDefault();
                    //var director = _userDb.Users.Where(u => u.userId == costCenter.vpId).SingleOrDefault();
                    var manager  = _userDb.Users.Where(u => u.userId == managerId).SingleOrDefault();
                    var director = _userDb.Users.Where(u => u.userId == directorId).SingleOrDefault();


                    if (supervisor == null)
                    {
                        string errorMessage = "Supervisor is missing or not set.";
                        Helpers.Mailer.SendExceptionDetail("post:/api/signatures/create", errorMessage, string.Empty, userDetails.userName, value);
                        throw new Exception(errorMessage);
                    }
                    else
                    {
                        Models.ReportSign supervisorSignature = new Models.ReportSign();

                        supervisorSignature.incidentId        = value.reportId;
                        supervisorSignature.reportSigUserId   = supervisor.userId;
                        supervisorSignature.staffName         = string.Format("{0} {1}", supervisor.firstName, supervisor.lastName);
                        supervisorSignature.staffTitle        = supervisor.jobTitle;
                        supervisorSignature.reportSigType     = "U";
                        supervisorSignature.approvalStatusId  = 1;
                        supervisorSignature.reportSigCreated  = DateTime.Now;
                        supervisorSignature.incidentMedicalId = 0;


                        this._db.ReportSigns.Add(supervisorSignature);
                        this._db.SaveChanges();

                        sendTos.Add(supervisor.eMail);
                    }

                    if (costCenter == null)
                    {
                        string errorMessage = "Cost Center was not found for user.";
                        Helpers.Mailer.SendExceptionDetail("post:/api/signatures/create", errorMessage, string.Empty, userDetails.userName, value);
                        throw new Exception(errorMessage);
                    }



                    if (manager != null)
                    {
                        Models.ReportSign managerSignature = new Models.ReportSign();

                        managerSignature.incidentId        = value.reportId;
                        managerSignature.reportSigUserId   = manager.userId;
                        managerSignature.staffName         = string.Format("{0} {1}", manager.firstName, manager.lastName);
                        managerSignature.staffTitle        = manager.jobTitle;
                        managerSignature.reportSigType     = "M";
                        managerSignature.approvalStatusId  = 1;
                        managerSignature.reportSigCreated  = DateTime.Now;
                        managerSignature.incidentMedicalId = 0;


                        this._db.ReportSigns.Add(managerSignature);
                        this._db.SaveChanges();

                        sendTos.Add(manager.eMail);
                    }



                    if (director != null)
                    {
                        Models.ReportSign directorSignature = new Models.ReportSign();

                        directorSignature.incidentId        = value.reportId;
                        directorSignature.reportSigUserId   = director.userId;
                        directorSignature.staffName         = string.Format("{0} {1}", director.firstName, director.lastName);
                        directorSignature.staffTitle        = director.jobTitle;
                        directorSignature.reportSigType     = "D";
                        directorSignature.approvalStatusId  = 1;
                        directorSignature.reportSigCreated  = DateTime.Now;
                        directorSignature.incidentMedicalId = 0;


                        this._db.ReportSigns.Add(directorSignature);
                        this._db.SaveChanges();

                        sendTos.Add(director.eMail);
                    }



                    // SEND NOTIFICATION E-MAIL TO ALL
                    Controllers.ReportsController reportsController = new Controllers.ReportsController();
                    Stream reportStream   = reportsController.IncidentReport(value.reportId).FileStream;
                    string attachmentName = "Incident Report.pdf";


                    StringBuilder messageBody = new StringBuilder();
                    messageBody.Append("<h1>Incident Report</h1>");
                    messageBody.Append("<p>An incident report has been submitted by " + report.staffName + " for client " + report.clientName + ".");
                    messageBody.Append("Please review attached report.</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidentsnr\">Click here to access the incident reports application.</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidentsnr/incidents/review/" + value.reportId + "\"> Click here to access the incident report directly.</p>");


                    Helpers.Mailer.SendNotificationEmail(sendTos, "Incident Report Posted", messageBody.ToString(), reportStream, attachmentName);

                    reportStream.Dispose();
                    reportsController.Dispose();
                }  // if userDetails == null



                _userDb.Dispose();
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMessage += Environment.NewLine + ex.InnerException.Message;
                }

                string currentUser = RequestContext.Principal.Identity.Name;

                Helpers.Mailer.SendExceptionDetail("post:/api/signatures/create", errorMessage, ex.StackTrace, value.userId.ToString(), value);


                throw new Exception(errorMessage);
            }
        }
예제 #5
0
        public void AddCooToReport([FromBody] long id)
        {
            var           signatures = this._db.ReportSigns.Where(s => s.incidentId == id && s.reportSigType == "O");
            List <string> sendTos    = new List <string>();

            if (signatures.Count() == 0)
            {
                var notifiers = this._db.SpecialNotifiers.Where(n => n.notifierType == "COO");

                if (notifiers.Count() > 0)
                {
                    foreach (var notifier in notifiers)
                    {
                        var coo = new Models.ReportSign();
                        coo.incidentId        = id;
                        coo.approvalStatusId  = 1;
                        coo.reportSigType     = "O";
                        coo.staffName         = notifier.notifierName;
                        coo.staffTitle        = notifier.notifierTitle;
                        coo.reportSigUserId   = notifier.notifierUserId;
                        coo.reportSigCreated  = DateTime.Now;
                        coo.incidentMedicalId = 0;

                        this._db.ReportSigns.Add(coo);

                        sendTos.Add(notifier.notifierEmail);



                        var notification = new Models.Notification();

                        notification.incidentId     = id;
                        notification.notifyPartyId  = 4; // COO
                        notification.notifyDateTime = DateTime.Now;
                        notification.notifyContact  = notifier.notifierName;
                        notification.notifyMethod   = "Automatic E-mail";
                        notification.notifyStaffId  = notifier.notifierUserId;

                        this._db.Notifications.Add(notification);
                    }


                    this._db.SaveChanges();


                    Controllers.ReportsController reportsController = new Controllers.ReportsController();
                    Stream reportStream   = reportsController.IncidentReport(id).FileStream;
                    string attachmentName = "Incident Report.pdf";


                    StringBuilder messageBody = new StringBuilder();
                    messageBody.Append("<h1>Incident Report</h1>");
                    messageBody.Append("<p>You have been added to an incident report.  Please review attached report.</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidentsnr\">Click here to access the incident reports application.</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidentsnr/incidents/review/" + id + "\"> Click here to access this incident report.</p>");


                    Helpers.Mailer.SendNotificationEmail(sendTos, "COO Notification", messageBody.ToString(), reportStream, attachmentName);

                    reportStream.Dispose();
                    reportsController.Dispose();
                }
            }
        }