Example #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                DAL.DAL_Notification dal_NoTi = new DAL.DAL_Notification();

                DateTime   dateNext    = DateTime.Today.AddDays(1);
                var        arrayUser   = new DAL.DAL_User().GetFromAppointmentDate(dateNext);
                string     html        = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplate/EmailTemplate.html"), System.Text.Encoding.UTF8);
                Attachment oAttachment = new Attachment(System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplate/logoSendMail.png"));

                oAttachment.ContentId = Guid.NewGuid().ToString().Trim();
                DAL.DAL_Messages dal_message = new DAL.DAL_Messages();

                string strBase64 = string.Empty;

                using (Image image = Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplate/logoSendMail.png")))
                {
                    using (MemoryStream m = new MemoryStream())
                    {
                        image.Save(m, image.RawFormat);
                        byte[] imageBytes = m.ToArray();
                        strBase64 = "data:image/png;base64," + Convert.ToBase64String(imageBytes);
                    }
                }

                foreach (var recepient in arrayUser)
                {
                    MailMessage message = new MailMessage();
                    message.Attachments.Add(oAttachment);
                    message.From = new MailAddress(ConfigurationManager.AppSettings["User-NetworkCredential"]);
                    message.To.Add(recepient.Email);
                    message.Subject    = "Reminder of Appointment on " + dateNext.ToString("dd/MM/yyyy");
                    message.Body       = html.Replace("{IdLogo}", oAttachment.ContentId).Replace("{Subject}", "Reminder of Appointment on " + dateNext.ToString("dd/MM/yyyy")).Replace("{Body}", "NRIC " + Trinity.Common.CommonUtil.GetQueueNumber(recepient.NRIC) + ", you have been scheduled for urine reporting at CNB ENF A on " + DateTime.Today.ToString("dd/MM/yyyy"));
                    message.IsBodyHtml = true;
                    // Send the email async to avoid blocking the main thread
                    SmtpClient client = new SmtpClient();
                    client.Host = ConfigurationManager.AppSettings["Host"];
                    client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
                    client.UseDefaultCredentials = false;
                    client.EnableSsl             = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
                    client.Credentials           = new NetworkCredential(ConfigurationManager.AppSettings["User-NetworkCredential"], ConfigurationManager.AppSettings["Password-NetworkCredential"]);

                    client.SendCompleted += (se, ea) =>
                    {
                        client.Dispose();
                        message.Dispose();
                        dal_message.Insert(recepient, message.Subject, message.Body, true);
                        dal_message.Insert(recepient, message.Subject, "NRIC " + Trinity.Common.CommonUtil.GetQueueNumber(recepient.NRIC) + ", you have been scheduled for urine reporting at CNB ENF A on " + DateTime.Today.ToString("dd/MM/yyyy"), false);
                    };

                    client.SendAsync(message, null);
                    //Send notification
                    dal_NoTi.InsertNotification(null, recepient.UserId, message.Subject, message.Body.Replace("cid:" + oAttachment.ContentId, strBase64), false, DateTime.Now, null, EnumNotificationTypes.Notification, EnumStation.DUTYOFFICER);
                }
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        public async System.Threading.Tasks.Task <IHttpActionResult> SHPPostNotification([FromBody] SHPNotificationModel data)
        {
            try
            {
                string Subject = data.Content;
                if (Subject.Length > 100)
                {
                    Subject = Subject.Substring(0, 96) + " ...";
                }
                string IDNoti = new DAL.DAL_Notification().InsertNotification(null, null, Subject, data.Content, false, data.Datetime.Value, data.notification_code, data.Type, EnumStation.SHP);
                if (string.IsNullOrEmpty(IDNoti))
                {
                    //return Ok(string.Empty);
                    return(Ok(false));
                }
                else
                {
                    await System.Threading.Tasks.Task.Run(() => Trinity.SignalR.Client.Instance.SendToAppDutyOfficers(null, Subject, data.Content, data.Type, EnumStation.SHP, false, IDNoti));

                    //return Ok(IDNoti);
                    return(Ok(true));
                }
            }
            catch (Exception)
            {
                return(Ok(false));
            }
        }
Example #3
0
        /// <summary>
        /// Case Officer use this API to send notifications to supervisee
        /// </summary>
        /// <param name="fromUserId"></param>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        /// <param name="notificationType"></param>
        public void SendToSupervisee(string fromUserId, string toUserId, string subject, string content, string notificationType)
        {
            string result = new DAL.DAL_Notification().InsertNotification(fromUserId, toUserId, subject, content, true, DateTime.Now, null, notificationType, Station);

            if (!string.IsNullOrEmpty(result))
            {
                NotificationInfo notificationInfo = new NotificationInfo()
                {
                    Name       = NotificationNames.ALERT_MESSAGE,
                    FromUserId = fromUserId,
                    ToUserIds  = new string[] { toUserId },
                    Content    = content,
                    Subject    = subject,
                    Type       = notificationType,
                    Source     = Station
                };
                PostNotification(notificationInfo);
            }
        }
Example #4
0
        public void SendToDutyOfficer(string fromUserId, string dutyOfficerID, string subject, string content, string notificationType)
        {
            string NotificationID = Guid.NewGuid().ToString().Trim();
            int    result         = new DAL.DAL_Notification().SendToDutyOfficer(NotificationID, fromUserId, dutyOfficerID, subject, content, notificationType, Station);

            if (result > 0)
            {
                NotificationInfo notificationInfo = new NotificationInfo()
                {
                    Name           = NotificationNames.ALERT_MESSAGE,
                    FromUserId     = fromUserId,
                    ToUserIds      = new string[] { dutyOfficerID },
                    Content        = content,
                    Subject        = subject,
                    Type           = notificationType,
                    Source         = Station,
                    NotificationID = NotificationID
                };
                PostNotification(notificationInfo);
            }
        }
Example #5
0
        public async System.Threading.Tasks.Task <IHttpActionResult> SSPPostNotification([FromBody] SSPNotificationModel data)
        {
            try
            {
                LogManager.Debug(string.Format("Begin SSPPostNotification, NRIC:{0}, Type:{1}, Datetime:{2}, Notification_Code:{3}, Content:{4}", data.NRIC, data.Type, data.Datetime, data.notification_code, data.Content));
                Trinity.DAL.DBContext.Membership_Users user = null;
                if (!string.IsNullOrEmpty(data.NRIC))
                {
                    user = new DAL.DAL_User().GetByNRIC(data.NRIC);
                }
                string Subject = data.Content;
                if (Subject.Length > 100)
                {
                    Subject = Subject.Substring(0, 96) + " ...";
                }
                string IDNoti = new DAL.DAL_Notification().InsertNotification(user != null ? user.UserId : null, null, Subject, data.Content, false, data.Datetime, data.notification_code, data.Type, EnumStation.SSP);
                if (!string.IsNullOrEmpty(IDNoti))
                {
                    if (data.Type == EnumNotificationTypes.Error && user != null)
                    {
                        new DAL.DAL_QueueNumber().UpdateQueueStatusByUserId(user.UserId, EnumStation.SSP, EnumQueueStatuses.Errors, EnumStation.DUTYOFFICER, EnumQueueStatuses.Finished, EnumMessage.LeakageDeletected, EnumQueueOutcomeText.Processing);

                        await System.Threading.Tasks.Task.Run(() => Trinity.SignalR.Client.Instance.BackendAPISend(NotificationNames.SSP_ERROR, data.NRIC));
                    }
                    await System.Threading.Tasks.Task.Run(() => Trinity.SignalR.Client.Instance.SendToAppDutyOfficers((user != null ? user.UserId : null), Subject, data.Content, data.Type, EnumStation.SSP, false, IDNoti));

                    LogManager.Debug("SSPPostNotification completed successfully");
                    return(Ok(true));
                }
                else
                {
                    LogManager.Error("SSPPostNotification failed.");
                    return(Ok(false));
                }
            }
            catch (Exception)
            {
                return(Ok(false));
            }
        }