/// <summary>
    /// Initializes doctor's dropdown list
    /// </summary>
    private void InitializeDoctorsDropdown()
    {
        // Try to get the data from cache
        var doctors = CacheHelper.Cache(
            cs =>
        {
            // Get all doctors
            var result = DoctorInfoProvider.GetDoctors()
                         .Columns("DoctorID", "DoctorFirstName", "DoctorLastName");

            // Setup the cache dependencies only when caching is active
            if (cs.Cached)
            {
                // Flush the cache if any doctor is changed
                cs.CacheDependency = CacheHelper.GetCacheDependency("DoctorAppointments.Doctor|all");
            }
            return(result);
        },
            // cache for 10 minutes
            new CacheSettings(10, "DoctorList")
            );


        // Get all doctors
        foreach (var doctor in doctors)
        {
            // Add each doctor to dropdown list
            var listItem = new ListItem(String.Format("{0} {1}", doctor.DoctorFirstName, doctor.DoctorLastName), ValidationHelper.GetString(doctor.DoctorID, String.Empty));
            SelectDoctor.Items.Add(listItem);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Executed whenever a new record of AppointmentInfo class is inserted
    /// </summary>
    public static void Insert_After(object sender, ObjectEventArgs e)
    {
        // Cast object to AppoinmentInfo class so that we can access its properties
        var appointment = (AppointmentInfo)e.Object;

        // Get DoctorInfo in order to retrieve his e-mail
        var doctor = DoctorInfoProvider.GetDoctorInfo(appointment.AppointmentDoctorID);

        if (doctor != null)
        {
            // Prepare body of e-mail
            var plainTextBody = $"There is a new appointment request by {appointment.AppointmentPatientFirstName} {appointment.AppointmentPatientLastName} for {appointment.AppointmentDate.ToShortDateString()}. Please get back to patient with available dates on e-mail address {appointment.AppointmentPatientEmail}";

            var htmlBody = $"<h1>New appointment</h1><p>There is a new appointment request by {appointment.AppointmentPatientFirstName} {appointment.AppointmentPatientLastName} for {appointment.AppointmentDate.ToShortDateString()}. Please get back to patient with available dates on e-mail address {appointment.AppointmentPatientEmail}</p>";

            // Create e-mail
            var email = new EmailMessage()
            {
                Subject       = $"New appointment: {appointment.AppointmentPatientFirstName} {appointment.AppointmentPatientLastName}",
                Recipients    = doctor.DoctorEmail,
                PlainTextBody = plainTextBody,
                Body          = htmlBody,
                From          = "*****@*****.**"
            };

            // Send e-mail
            EmailSender.SendEmail(email);
        }
    }
    protected void btnAddDoctor_Click(object sender, EventArgs e)
    {
        // Create new DoctorInfo object
        var doctor = new DoctorInfo();

        doctor.DoctorFirstName    = "John";
        doctor.DoctorLastName     = "Smith";
        doctor.DoctorCodeName     = "JohnSmith";
        doctor.DoctorEmail        = "*****@*****.**";
        doctor.DoctorSpecialty    = "Family Medicine";
        doctor.DoctorLastModified = DateTime.Now;

        // Insert doctor
        DoctorInfoProvider.SetDoctorInfo(doctor);

        Response.Write(doctor.DoctorFirstName + " " + doctor.DoctorLastName + " was added.");
    }