/// <summary> /// Generates notifications for new Medical Appointments /// </summary> private static void GenerateNotificationsForNewGenericAppointments( [NotNull] CerebelloEntities db, DateTime referenceTime, [NotNull] ICollection <Tuple <Notification, object> > notificationsToBeDispatched) { if (db == null) { throw new ArgumentNullException("db"); } if (notificationsToBeDispatched == null) { throw new ArgumentNullException("notificationsToBeDispatched"); } // check for appointments that have to be notified var timeOffset = referenceTime.AddMinutes(30); var unnotifiedAppointments = db.Appointments.Where( a => !a.Notified && a.Type == (int)TypeAppointment.GenericAppointment && a.Start >= referenceTime && a.Start < timeOffset).ToList(); foreach (var appointment in unnotifiedAppointments) { Debug.Assert(appointment.PatientId != null, "appointment.PatientId != null"); var genericAppointmentData = new GenericAppointmentNotificationData() { Text = appointment.Description, Time = DateTimeHelper.GetFormattedTime( PracticeController.ConvertToLocalDateTime(appointment.Practice, appointment.Start)) }; var genericAppointmentDataString = new JavaScriptSerializer().Serialize(genericAppointmentData); // notify the doctor var newNotification = new Notification() { CreatedOn = referenceTime, IsClosed = false, UserToId = appointment.DoctorId, Type = NotificationConstants.GENERIC_APPOINTMENT_NOTIFICATION_TYPE, PracticeId = appointment.PracticeId, Data = genericAppointmentDataString }; appointment.Doctor.Users.First().Notifications.Add(newNotification); notificationsToBeDispatched.Add(new Tuple <Notification, object>(newNotification, genericAppointmentData)); appointment.Notified = true; } db.SaveChanges(); }
/// <summary> /// Generates notifications for new Medical Appointments /// </summary> private static void GenerateNotificationsForNewGenericAppointments( [NotNull] CerebelloEntities db, DateTime referenceTime, [NotNull] ICollection<Tuple<Notification, object>> notificationsToBeDispatched) { if (db == null) throw new ArgumentNullException("db"); if (notificationsToBeDispatched == null) throw new ArgumentNullException("notificationsToBeDispatched"); // check for appointments that have to be notified var timeOffset = referenceTime.AddMinutes(30); var unnotifiedAppointments = db.Appointments.Where( a => !a.Notified && a.Type == (int)TypeAppointment.GenericAppointment && a.Start >= referenceTime && a.Start < timeOffset).ToList(); foreach (var appointment in unnotifiedAppointments) { Debug.Assert(appointment.PatientId != null, "appointment.PatientId != null"); var genericAppointmentData = new GenericAppointmentNotificationData() { Text = appointment.Description, Time = DateTimeHelper.GetFormattedTime( PracticeController.ConvertToLocalDateTime(appointment.Practice, appointment.Start)) }; var genericAppointmentDataString = new JavaScriptSerializer().Serialize(genericAppointmentData); // notify the doctor var newNotification = new Notification() { CreatedOn = referenceTime, IsClosed = false, UserToId = appointment.DoctorId, Type = NotificationConstants.GENERIC_APPOINTMENT_NOTIFICATION_TYPE, PracticeId = appointment.PracticeId, Data = genericAppointmentDataString }; appointment.Doctor.Users.First().Notifications.Add(newNotification); notificationsToBeDispatched.Add(new Tuple<Notification, object>(newNotification, genericAppointmentData)); appointment.Notified = true; } db.SaveChanges(); }