public void Post([FromBody] List <Models.ReportIncident> incidents)
        {
            var incidentTypes = this._db.IncidentTypes.Where(t => t.incidentReportTypeId == 1).ToList();


            foreach (Models.ReportIncident incident in incidents)
            {
                this._db.ReportIncidents.Add(incident);
                this._db.SaveChanges();

                var incidentType = incidentTypes.Where(t => t.incidentTypeId == incident.incidentTypeId).SingleOrDefault();

                if (incidentType != null)
                {
                    if (incidentType.incidentCategoryId == 1 || incidentType.incidentCategoryId == 2) // REPORTABLE TO JC
                    {
                        ReportsController reportsController         = new ReportsController();
                        Models.Presentation.ReportsViewModel report = reportsController.GetReportHeader(incident.incidentId);
                        reportsController.Dispose();


                        Controllers.MailController mailer = new MailController();

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

                        sendTos.Add("*****@*****.**");

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

                        notification.incidentId        = incident.incidentId;
                        notification.notifyPartyId     = 37;
                        notification.notifyDateTime    = DateTime.Now;
                        notification.notifyContact     = "CFS Compliance";
                        notification.notifyMethod      = "E-Mail";
                        notification.notifyStaffId     = 0;
                        notification.notifyComments    = "Automatic E-Mail sent to compliance by incident report system.";
                        notification.isAcknowledged    = 1;
                        notification.acknowledgeUserId = 0;

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

                        msg.Append("<h1>Incident Report: Compliance Notification</h1>");
                        msg.Append("<p>A new incident report for client " + report.clientName + " by " + report.staffName + " has been created and is being forwarded to compliance.</p>");
                        msg.Append("<p><a href=\"http://cfs-incidents/Admin/Review/" + report.incidentId.ToString() + "\">Click here to view the report.</a></p>");


                        //sendTos.Add(notifier.emailAddress);
                        //sendTos.Add("*****@*****.**"); //MTS - commented out March '18
                        mailer.SendMail(sendTos, "*****@*****.**", "Incident Report Compliance Notification: " + report.clientName, System.Net.Mail.MailPriority.High, msg);
                    }
                }
            }
        }
        // POST api/<controller>
        public void Post([FromBody] Models.Notification notification)
        {
            if (notification.notificationId == 0)
            {
                this._db.Notifications.Add(notification);
            }
            else
            {
                this._db.Notifications.Attach(notification);
                this._db.Entry(notification).State = System.Data.Entity.EntityState.Modified;
            }

            this._db.SaveChanges();


            if (notification.notifyPartyId == 8)  // JUSTICE CENTER
            {
                ReportsController reportsController         = new ReportsController();
                Models.Presentation.ReportsViewModel report = reportsController.GetReportHeader(notification.incidentId);
                reportsController.Dispose();


                Controllers.MailController mailer = new MailController();

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

                sendTos.Add("*****@*****.**");

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

                complianceNotification.incidentId        = notification.incidentId;
                complianceNotification.notifyPartyId     = 37;
                complianceNotification.notifyDateTime    = DateTime.Now;
                complianceNotification.notifyContact     = "CFS Compliance";
                complianceNotification.notifyMethod      = "E-Mail";
                complianceNotification.notifyStaffId     = 0;
                complianceNotification.notifyComments    = "Automatic E-Mail sent to compliance by incident report system.";
                complianceNotification.isAcknowledged    = 1;
                complianceNotification.acknowledgeUserId = 0;

                this._db.Notifications.Add(complianceNotification);
                this._db.SaveChanges();

                msg.Append("<h1>Incident Report: Compliance Notification</h1>");
                msg.Append("<p>A new incident report for client " + report.clientName + " by " + report.staffName + " has been created and is being forwarded to compliance.</p>");
                msg.Append("<p><a href=\"http://cfs-incidents/admin/review/" + report.incidentId.ToString() + "\">Click here to view the report.</a></p>");


                //sendTos.Add(notifier.emailAddress);
                //sendTos.Add("*****@*****.**"); //MTS - commented out March '18
                mailer.SendMail(sendTos, "*****@*****.**", "Incident Report Compliance Notification: Justice Center Called", System.Net.Mail.MailPriority.High, msg);
            }
        }
        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();
        }