Exemplo n.º 1
0
        private static void SendSMS(DSModel db, SMSService sms, NotificationModel notice)
        {
            try
            {
                string senderNumber = GLOB.Settings.Get<string>(16);
                string[] managementNumbers = GLOB.Settings.Get<string>(17).Split(';');

                List<string> numbersToSend = new List<string>();
                if (notice.ReminderType == (uint)ReminderType.Driver || notice.ReminderType == (uint)ReminderType.MVR)
                    numbersToSend.Add("1" + notice.CellPhone.Replace("-", string.Empty).Replace(" ", string.Empty).Trim());
                if (notice.ReminderType == (uint)ReminderType.Management || notice.ReminderType == (uint)ReminderType.MVR)
                    numbersToSend.AddRange(managementNumbers);

                bool status = false;
                foreach (string number in numbersToSend)
                {
                    try
                    {
                        if (sms.SendSMS(senderNumber, number, notice.Message))
                            status = true;
                    }
                    catch { }
                }

                NotificationRepository.UpdateNotificationStatus(db, notice, status);
            }
            catch { }
        }
Exemplo n.º 2
0
        private static void SendEmail(DSModel db, EmailService email, NotificationModel notice)
        {
            try
            {
                string senderEmail = GLOB.Settings.Get<string>(20);
                string[] managementEmails = GLOB.Settings.Get<string>(21).Split(';');

                List<string> emailsToSend = new List<string>();
                if (notice.ReminderType == (uint)ReminderType.Driver || notice.ReminderType == (uint)ReminderType.MVR)
                    emailsToSend.Add(notice.Email);
                if (notice.ReminderType == (uint)ReminderType.Management || notice.ReminderType == (uint)ReminderType.MVR)
                    emailsToSend.AddRange(managementEmails);

                bool status = false;
                foreach (string address in emailsToSend)
                {
                    try
                    {
                        if (!email.SendEmail(senderEmail, address, notice.Message, notice.Message).Result.Failed)
                            status = true;
                    }
                    catch { }
                }

                NotificationRepository.UpdateNotificationStatus(db, notice, status);
            }
            catch { }
        }
        /// <summary>
        /// Updates the status of the reminder (has been notified or not)
        /// </summary>
        /// <param name="db">Database</param>
        /// <param name="model">Notification</param>
        /// <param name="status">Has sent notification</param>
        public static void UpdateNotificationStatus(DSModel db, NotificationModel model, bool status)
        {
            if (db == null)
                throw new ArgumentNullException("db");
            if (model == null)
                throw new ArgumentNullException("model");

            if (model.NotificationTypeID == (uint)NotificationType.Medical)
            {
                db.DriversMedicalsReminders
                    .Where(r => r.DriverMedicalReminderID == model.NotificationID)
                    .UpdateAll(u => u.Set(r => r.HasSentReminder, r => status));
            }
            else if (model.NotificationTypeID == (uint)NotificationType.License)
            {
                db.DriversLicensesReminders
                    .Where(r => r.DriverLicenseReminderID == model.NotificationID)
                    .UpdateAll(u => u.Set(r => r.HasSentReminder, r => status));
            }
        }