Exemple #1
0
        public void EmptyParametersTest()
        {
            MailController mailController = null;

            try
            {
                mailController = CreateMailController();
                mailController.Start(MailServerType.Imap, MailServerEncryption.SslTls, "", "", "");
            }
            catch (Exception e)
            {
                mailController?.Dispose();
                return;
            }

            Assert.Fail();
        }
Exemple #2
0
 public void Dispose()
 {
     _mailController?.Dispose();
 }
        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.");
                }
            }
        }
        public long Post([FromBody] Models.IncidentReport report)
        {
            if (report.userId == 0)
            {
                SessionController session = new SessionController();
                var user = session.Get();

                report.userId         = user.userId;
                report.createdStation = user.stationInfo;
                report.currentUser    = user.userId;

                session.Dispose();
            }

            if (report.incidentId == 0)
            {
                // CREATE REPORT
                this._db.IncidentReports.Add(report);
            }
            else
            {
                this._db.IncidentReports.Attach(report);
                this._db.Entry(report).State = System.Data.Entity.EntityState.Modified;
            }

            try
            {
                this._db.SaveChanges();


                // WRITE TO REPORT LOG
                Models.ReportLog log = new Models.ReportLog();
                log.incidentId  = report.incidentId;
                log.userId      = report.userId;
                log.userStation = report.createdStation;
                log.logDateTime = DateTime.Now;
                log.logDetails  = "Report created.";

                LogController logController = new LogController();
                logController.Post(log);
                logController.Dispose();


                // NOTIFY
                MailController mailer = new MailController();



                StringBuilder messageBody = new StringBuilder();

                messageBody.Append("<p>A new incident report for <b>" + report.clientName + "</b> has been created 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>");

                if (report.incidentReportTypeId == 1)
                {
                    mailer.SendMail(
                        new List <string>()
                    {
                        "*****@*****.**"
                    },
                        "*****@*****.**",
                        "New Incident Report",
                        System.Net.Mail.MailPriority.High,
                        messageBody
                        );
                }
                else
                {
                    mailer.SendMail(
                        new List <string>()
                    {
                        "*****@*****.**"
                    },
                        "*****@*****.**",
                        "New Incident Report",
                        System.Net.Mail.MailPriority.High,
                        messageBody
                        );
                }

                mailer.Dispose();

                return(report.incidentId);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);


                MailController mailer = new MailController();
                mailer.SendMail(
                    new List <string>()
                {
                    "*****@*****.**"
                },
                    "*****@*****.**",
                    "ERROR CREATING INCIDENT: VALIDATION",
                    System.Net.Mail.MailPriority.High,
                    exceptionMessage
                    );

                string currentUser = RequestContext.Principal.Identity.Name;

                mailer.SendExceptionDetail("post:/api/reports", exceptionMessage, ex.StackTrace, currentUser, report);


                // Throw a new DbEntityValidationException with the improved exception message.
                throw new System.Data.Entity.Validation.DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMessage += " Inner Exception: " + ex.InnerException;
                }

                MailController mailer = new MailController();
                mailer.SendMail(
                    new List <string>()
                {
                    "*****@*****.**"
                },
                    "*****@*****.**",
                    "ERROR CREATING INCIDENT",
                    System.Net.Mail.MailPriority.High,
                    errorMessage
                    );

                string currentUser = RequestContext.Principal.Identity.Name;

                mailer.SendExceptionDetail("post:/api/reports", errorMessage, ex.StackTrace, currentUser, report);

                throw new Exception(errorMessage);
            }
        }
        public void PostAutoNotifiers([FromBody] Models.Presentation.ProgramNotifiersModel[] notifiers)
        {
            Controllers.MailController mailer = new MailController();

            long incidentId = 0;

            incidentId = notifiers.FirstOrDefault().incidentId;



            ReportsController reportsController = new ReportsController();

            Models.Presentation.ReportsViewModel report = reportsController.GetReportHeader(incidentId);
            reportsController.Dispose();


            List <string> sendTos = new List <string>();
            StringBuilder msg     = new StringBuilder();

            //sendTos.Add(notifier.emailAddress);
            sendTos.Add("*****@*****.**");

            msg.Append("<h1>New Incident Report</h1>");
            msg.Append("<p>A new incident report has been created for client " + report.clientName + " by " + report.staffName + ".</p>");
            msg.Append("<p><a href=\"http://cfs-incidents/report/residential/" + report.incidentId.ToString() + "\">Click here to view the report.</a></p>");
            msg.Append("<p><a href=\"http://cfs-incidents/Medicals\">Click here to create a medical review.</a></p>");

            // COMMENT OUT BEFORE LIVE
            //msg.Append("<p>To be included:<br />");


            foreach (var notifier in notifiers)
            {
                //msg.Append(notifier.emailAddress + "<br />");

                sendTos.Add(notifier.emailAddress.ToLower().Trim());

                Models.Notification notification = new Models.Notification();

                notification.incidentId        = incidentId;
                notification.notifyPartyId     = notifier.notifyPartyId;
                notification.notifyDateTime    = DateTime.Now;
                notification.notifyContact     = notifier.staffName;
                notification.notifyMethod      = "E-Mail";
                notification.notifyStaffId     = notifier.userId == null ? 0 : (long)notifier.userId;
                notification.notifyComments    = "Automatic E-Mail sent to " + notifier.emailAddress.ToLower().Trim() + " by incident report system.";
                notification.isAcknowledged    = 1;
                notification.acknowledgeUserId = notifier.userId == null ? 0 : (long)notifier.userId;

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


            this._db.SaveChanges();


            // COMMENT OUT BEFORE LIVE
            //msg.Append("</p>");


            // ADD REPORT DETAILS AND LINK TO REPORT


            // ACKNOWLEDGEMENT LINK
            msg.Append("<p><a href='/'></a></p>");


            mailer.SendMail(sendTos, "*****@*****.**", "New Incident Report: " + report.clientName, System.Net.Mail.MailPriority.High, msg);



            mailer.Dispose();
        }