/// <summary> /// Loads a page of appointments. /// </summary> /// <param name="moduleId">The ID of the module to which the appointments belong.</param> /// <param name="isAccepted"> /// <c>true</c> to retrieve only accepted appointments, /// <c>false</c> to retrieve only declines appointments, /// or <c>null</c> to retrieve only those appointments which have been neither accepted nor declined. /// </param> /// <param name="sortExpression">The property by which the appointments should be sorted.</param> /// <param name="pageIndex">The index of the page of appointments.</param> /// <param name="pageSize">Size of the page of appointments.</param> /// <returns> /// A page of appointments. /// </returns> /// <exception cref="DBException">if there's an error while going to the database to retrieve the appointments</exception> private static AppointmentCollection Load(int moduleId, bool?isAccepted, string sortExpression, int?pageIndex, int?pageSize) { using (IDataReader reader = AppointmentSqlDataProvider.GetAppointments(moduleId, isAccepted, sortExpression, pageSize, pageIndex)) { return(FillAppointments(reader, pageSize)); } }
/// <summary> /// Loads all appointment types /// </summary> /// <param name="moduleId"> The module Id. </param> /// <returns> /// A collection of appointment types. /// </returns> internal static AppointmentTypeCollection Load(int moduleId) { using (var reader = AppointmentSqlDataProvider.GetAppointmentTypes(moduleId)) { return(FillAppointmentTypes(reader)); } }
/// <summary> /// Loads the <see cref="Appointment"/> with the specified <paramref name="appointmentId"/>. /// </summary> /// <param name="appointmentId">The ID of the <see cref="Appointment"/> to load.</param> /// <returns>The <see cref="Appointment"/> instance with the given <paramref name="appointmentId"/>, or <c>null</c> if no <see cref="Appointment"/> exists with that ID</returns> public static Appointment Load(int appointmentId) { using (IDataReader reader = AppointmentSqlDataProvider.GetAppointment(appointmentId)) { if (reader.Read()) { return(Fill(reader)); } return(null); } }
/// <summary> /// Gets the appointment type with the given <paramref name="appointmentTypeId"/>. /// </summary> /// <param name="appointmentTypeId">The ID of the appointment type.</param> /// <param name="moduleId">The module id.</param> /// <returns>An <see cref="AppointmentType"/> instance</returns> public static AppointmentType Load(int appointmentTypeId, int moduleId) { using (var appointmentTypeReader = AppointmentSqlDataProvider.GetAppointmentType(appointmentTypeId, moduleId)) { if (appointmentTypeReader.Read()) { return(Fill(appointmentTypeReader)); } } return(null); }
/// <summary> /// Accepts or declines an <see cref="Appointment"/> via the given <paramref name="actionKey"/>. /// </summary> /// <param name="actionKey">The key the corresponds to accepting or declining a specific <see cref="Appointment"/>.</param> /// <returns><c>true</c> if the appointment was accepted, otherwise <c>false</c></returns> public static Appointment ApproveByKey(Guid actionKey) { using (IDataReader reader = AppointmentSqlDataProvider.ApproveByKey(actionKey)) { if (reader.Read()) { return(Fill(reader)); } return(null); } }
/// <summary> /// Determines whether an <see cref="Appointment"/> can be created at the specified <paramref name="start"/> time until the specified <paramref name="end"/> time. /// </summary> /// <param name="moduleId">The ID of the module in which the appointment is to be created.</param> /// <param name="start">The start of the new <see cref="Appointment"/>.</param> /// <param name="end">The end of the new <see cref="Appointment"/>.</param> /// <param name="max">The maximum appointments allowed for the specified time range</param> /// <returns> /// <c>true</c> if an <see cref="Appointment"/> can be created at the specified <paramref name="start"/> time until the specified <paramref name="end"/> time; otherwise, <c>false</c>. /// </returns> public static bool CanCreateAt(int moduleId, DateTime start, DateTime end, int?max) { var appointments = AppointmentSqlDataProvider.GetConcurrentAppointments(moduleId, start, end); var appointmentsInRange = new List <Appointment>(max ?? 10); while (appointments.Read()) { appointmentsInRange.Add(Fill(appointments)); } var uniqueStartTimes = appointmentsInRange.Select(apt => apt.StartDateTime).Distinct(); return(uniqueStartTimes.All(time => max > appointmentsInRange.Count(apt => time >= apt.StartDateTime && time < apt.EndDateTime))); }
/// <summary> /// Sends all queued emails /// </summary> public override void DoWork() { try { int successCount = 0; using (IDataReader queuedEmails = AppointmentSqlDataProvider.GetQueuedEmails()) { while (queuedEmails.Read()) { string result = SendMail( new PortalController().GetPortal((int)queuedEmails["PortalId"]).Email, queuedEmails["RecipientList"].ToString(), string.Empty, string.Empty, string.Empty, DotNetNuke.Services.Mail.MailPriority.Normal, queuedEmails["Subject"].ToString(), MailFormat.Html, Encoding.UTF8, queuedEmails["Body"].ToString(), new string[] { queuedEmails["Attachment"].ToString() }, string.Empty, string.Empty, string.Empty, string.Empty, "Y".Equals(HostSettings.GetHostSetting("SMTPEnableSSL"), StringComparison.Ordinal)); if (string.IsNullOrEmpty(result)) { AppointmentSqlDataProvider.ClearQueuedEmail((int)queuedEmails["QueueID"]); successCount++; } else { this.ScheduleHistoryItem.AddLogNote("QueueID " + queuedEmails["QueueID"].ToString() + " failed to send. SendMail error: " + result + "<br />"); } } } this.ScheduleHistoryItem.Succeeded = true; this.ScheduleHistoryItem.AddLogNote("Email Scheduler completed successfully. " + successCount + " emails sent.<br />"); } catch (Exception exc) { this.ScheduleHistoryItem.Succeeded = false; this.ScheduleHistoryItem.AddLogNote("Email Scheduler failed with the following error message: <br/>" + exc.Message + "<br />"); this.Errored(ref exc); } }
/// <summary> /// Queues an email to be sent later to the given email address with the given <paramref name="subject"/> and HTML <paramref name="body"/>. /// </summary> /// <param name="toList">The comma-or-semicolon-delimited list of email address(es) to which the email should be sent.</param> /// <param name="subject">The subject.</param> /// <param name="body">The HTML body.</param> /// <param name="attachment">The attachment.</param> private static void QueueEmail(string toList, string subject, string body, string attachment) { if (string.IsNullOrEmpty(toList)) { if (toList == null) { throw new ArgumentNullException("toList", "toList must have a value"); } else { throw new ArgumentException("toList must have a value", "toList"); } } AppointmentSqlDataProvider.QueueEmail(PortalController.GetCurrentPortalSettings().PortalId, toList, subject, body, attachment); }
/// <summary> /// Inserts this event. /// </summary> /// <param name="revisingUserId">The user who is inserting this event.</param> /// <exception cref="DBException">If an error occurs while going to the database to insert the event</exception> private void Insert(int revisingUserId) { using (var appointmentReader = AppointmentSqlDataProvider.InsertAppointment(this, revisingUserId)) { if (appointmentReader.Read()) { this.AppointmentId = (int)appointmentReader["AppointmentId"]; this.AcceptKey = (Guid)appointmentReader["AcceptKey"]; this.DeclineKey = (Guid)appointmentReader["DeclineKey"]; } else { throw new DBException("Result set was expected", "InsertAppointment"); } } }
/// <summary> /// Declines this <see cref="Appointment"/>. /// </summary> /// <param name="revisingUserId">The ID of the user declining the <see cref="Appointment"/>.</param> public void Decline(int revisingUserId) { AppointmentSqlDataProvider.DeclineAppointment(this.AppointmentId, revisingUserId); }
/// <summary> /// Accepts this <see cref="Appointment"/>. /// </summary> /// <param name="revisingUserId">The ID of the user accepting the <see cref="Appointment"/>.</param> public void Accept(int revisingUserId) { AppointmentSqlDataProvider.AcceptAppointment(this.AppointmentId, revisingUserId); }
/// <summary> /// Deletes the specified appointment id. /// </summary> /// <param name="appointmentId">The appointment id.</param> public static void Delete(int appointmentId) { AppointmentSqlDataProvider.DeleteAppointment(appointmentId); }
/// <summary> /// Updates this event. /// </summary> /// <param name="revisingUser">The user responsible for updating this event.</param> /// <exception cref="DBException">If an error occurs while going to the database to update the event</exception> private void Update(int revisingUser) { AppointmentSqlDataProvider.UpdateAppointment(this, revisingUser); }
/// <summary> /// Inserts the appointment type. /// </summary> /// <param name="revisingUser">The revising user.</param> /// <param name="moduleId">The module Id.</param> private void Insert(int revisingUser, int moduleId) { AppointmentSqlDataProvider.InsertAppointmentType(this, revisingUser, moduleId); }
/// <summary> /// Handles the <see cref="Button.Click"/> event of the <see cref="ExportButton"/> control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ExportButton_Click(object sender, EventArgs e) { var appointmentsTable = AppointmentSqlDataProvider.GetAppointmentsByDateRange(this.ModuleId, this.StartDatePicker.SelectedDate.Value, this.EndDatePicker.SelectedDate.Value); SendContentToClient(this.Response, "text/csv", CsvWriter.WriteToString(appointmentsTable, this.HeaderRowCheckBox.Checked, false), this.GetFileName()); }