protected void tbtnCreateAppointment_Click(object sender, EventArgs e) { string selectedDateTime = txtAppointmentDateTime.Value.Trim().ToString(); if (ddlDoctors.SelectedValue.Trim().ToString().Length < 1 || ddlSpecialities.SelectedValue.Trim().ToString().Length < 1) { Session["Message"] = "Doctor and Speciality are required"; Response.Redirect("CreateAppointment.aspx"); } Doctor doctor = _dc.Doctors.FirstOrDefault(dc => dc.FirstName + " " + dc.LastName == ddlDoctors.SelectedValue.Trim().ToString()); Speciality speciality = _dc.Specialities.FirstOrDefault(s => s.SpecialityName == ddlSpecialities.SelectedValue.Trim().ToString()); DoctorsAndSpeciality docAndSpec = _dc.DoctorsAndSpecialities.FirstOrDefault(ds => ds.DoctorsID == doctor.ID && ds.SpecialityID == speciality.ID); List <Appointment> appointmentsList = _dc.Appointments.Where(a => a.DoctorAndSpecialityID == docAndSpec.ID).ToList(); DateTime myDate; DateTime.TryParse(selectedDateTime, out myDate); foreach (var appointment in appointmentsList) { //selectedDate > appointment.AppointmentDate 1h DateTime now = DateTime.Now; DateTime plusOneHour = appointment.AppointmentDate.AddHours(1); DateTime minusOneHour = appointment.AppointmentDate.AddHours(-1); if (myDate < plusOneHour && myDate > minusOneHour) { Session["Message"] = "The doctor is Unavailable at that time."; Response.Redirect("CreateAppointment.aspx"); } } Appointment newAppointment = new Appointment(); newAppointment.UserID = Int32.Parse(Session["LoggedUserID"].ToString()); newAppointment.DoctorAndSpecialityID = docAndSpec.ID; newAppointment.AppointmentDate = myDate; try { _dc.Appointments.InsertOnSubmit(newAppointment); _dc.SubmitChanges(); } catch (Exception err) { Session["Message"] = err.Message.ToString(); Response.Redirect("CreateAppointment.aspx"); } Session["Message"] = "Success !"; Response.Redirect("Appointments.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (Session["Message"] != null) { lblMessage.Text = Session["Message"].ToString(); Session["Message"] = null; } if (Session["AppointmentID"] != null) { Appointment appointment = _dc.Appointments.FirstOrDefault(a => a.ID == Convert.ToInt32(Session["AppointmentID"].ToString())); DoctorsAndSpeciality docAndSpecs = _dc.DoctorsAndSpecialities.FirstOrDefault(d => d.ID == appointment.DoctorAndSpecialityID); // Doctor name Doctor doctorsName = _dc.Doctors.FirstOrDefault(d => d.ID == docAndSpecs.DoctorsID); //Speciality Speciality specialityName = _dc.Specialities.FirstOrDefault(d => d.ID == docAndSpecs.SpecialityID); lblDoctorsName.Text = doctorsName.FirstName.ToString() + " " + doctorsName.LastName.ToString(); lblDoctorSpeciality.Text = specialityName.SpecialityName.ToString(); } }
protected void tbtnCreateAppointment_Click(object sender, EventArgs e) { if (txtAppointmentDateTime.Value != null) { string selectedDateTime = txtAppointmentDateTime.Value.ToString(); DateTime myDate; DateTime.TryParse(selectedDateTime, out myDate); //get edited appointment Appointment appointment = _dc.Appointments.FirstOrDefault(a => a.ID == Convert.ToInt32(Session["AppointmentID"].ToString())); DoctorsAndSpeciality docAndSpec = _dc.DoctorsAndSpecialities.FirstOrDefault(ds => ds.ID == appointment.DoctorAndSpecialityID); List <Appointment> appointmentsList = _dc.Appointments.Where(a => a.DoctorAndSpecialityID == docAndSpec.ID).ToList(); foreach (var appt in appointmentsList) { //selectedDate > appointment.AppointmentDate 1h DateTime now = DateTime.Now; DateTime plusOneHour = appt.AppointmentDate.AddHours(1); DateTime minusOneHour = appt.AppointmentDate.AddHours(-1); if (myDate < plusOneHour && myDate > minusOneHour) { Session["Message"] = "The doctor is Unavailable at that time."; Response.Redirect("EditAppointment.aspx"); } } appointment.AppointmentDate = myDate; _dc.SubmitChanges(); } Response.Redirect("Appointments.aspx"); }
protected void btnRegister_Click(object sender, EventArgs e) { Doctor doctor = _dc.Doctors.FirstOrDefault(dc => dc.FirstName + " " + dc.LastName == ddlDoctors.SelectedValue.Trim().ToString()); Speciality speciality = _dc.Specialities.FirstOrDefault(s => s.SpecialityName == ddlSpecialities.SelectedValue.Trim().ToString()); DoctorsAndSpeciality CheckDoc = _dc.DoctorsAndSpecialities.FirstOrDefault(ds => ds.DoctorsID == doctor.ID && ds.SpecialityID == speciality.ID); if (CheckDoc == null) { DoctorsAndSpeciality docAndSpec = new DoctorsAndSpeciality(); docAndSpec.DoctorsID = doctor.ID; docAndSpec.SpecialityID = speciality.ID; _dc.DoctorsAndSpecialities.InsertOnSubmit(docAndSpec); _dc.SubmitChanges(); Session["Message"] = "Success !"; Response.Redirect("SetDoctorSpeciality.aspx"); } else { Session["Message"] = "The Doctor already has that speciality added"; Response.Redirect("SetDoctorSpeciality.aspx"); } }
private void detach_DoctorsAndSpecialities(DoctorsAndSpeciality entity) { this.SendPropertyChanging(); entity.Doctor = null; }
partial void DeleteDoctorsAndSpeciality(DoctorsAndSpeciality instance);
partial void UpdateDoctorsAndSpeciality(DoctorsAndSpeciality instance);
partial void InsertDoctorsAndSpeciality(DoctorsAndSpeciality instance);
private void attach_DoctorsAndSpecialities(DoctorsAndSpeciality entity) { this.SendPropertyChanging(); entity.Speciality = this; }
protected void Page_Load(object sender, EventArgs e) { if (Session["LoggedUserID"] != null) { User user = _dc.Users.FirstOrDefault(u => u.ID == Convert.ToInt32(Session["LoggedUserID"].ToString())); if (Session["Message"] != null) { lblMessage.Text = Session["Message"].ToString(); Session["Message"] = null; } if (user.Type != 1) { //Normal User btnCreateAppointment.Visible = true; List <Appointment> userAppointmentsList = _dc.Appointments.Where(a => a.UserID == Convert.ToInt32(Session["LoggedUserID"].ToString()) && a.IsDeleted == false).ToList(); int count = 1; foreach (Appointment userAppointment in userAppointmentsList) { Button btnDelete = new Button() { ID = userAppointment.ID.ToString() + "D", Text = "Delete", CssClass = "btn btn-danger" }; btnDelete.Click += buttonDelete_Click; Button btnEdit = new Button() { ID = userAppointment.ID.ToString() + "E", Text = "Edit", CssClass = "btn btn-warning" }; btnEdit.Click += buttonEdit_Click; TableRow row = new TableRow(); TableCell countNumber = new TableCell(); TableCell doctorCell = new TableCell(); TableCell specialityCell = new TableCell(); TableCell appointmentDateCell = new TableCell(); TableCell actionsCell = new TableCell(); //appointment date/time DateTime appointmentDate = userAppointment.AppointmentDate; DoctorsAndSpeciality docAndSpecs = _dc.DoctorsAndSpecialities.FirstOrDefault(d => d.ID == userAppointment.DoctorAndSpecialityID); // Doctor name Doctor doctorsName = _dc.Doctors.FirstOrDefault(d => d.ID == docAndSpecs.DoctorsID); //Speciality Speciality specialityName = _dc.Specialities.FirstOrDefault(d => d.ID == docAndSpecs.SpecialityID); countNumber.Text = count.ToString(); doctorCell.Text = doctorsName.FirstName.ToString() + " " + doctorsName.LastName.ToString(); specialityCell.Text = specialityName.SpecialityName.ToString(); appointmentDateCell.Text = appointmentDate.ToString(); actionsCell.Controls.Add(btnEdit); DateTime now = DateTime.Now; DateTime tomorrow = now.AddDays(1); if (appointmentDate > tomorrow) { actionsCell.Controls.Add(btnDelete); } row.Cells.Add(countNumber); row.Cells.Add(doctorCell); row.Cells.Add(specialityCell); row.Cells.Add(appointmentDateCell); row.Cells.Add(actionsCell); AppointmentsTable.Rows.Add(row); count++; } } else { //Admin List <Appointment> userAppointmentsList = _dc.Appointments.Where(a => a.IsDeleted == false).ToList(); int count = 1; foreach (Appointment userAppointment in userAppointmentsList) { Button btnDelete = new Button() { ID = userAppointment.ID.ToString() + "D", Text = "Delete", CssClass = "btn btn-danger" }; btnDelete.Click += buttonDelete_Click; Button btnEdit = new Button() { ID = userAppointment.ID.ToString() + "E", Text = "Edit", CssClass = "btn btn-warning" }; btnEdit.Click += buttonEdit_Click; TableRow row = new TableRow(); TableCell countNumber = new TableCell(); TableCell doctorCell = new TableCell(); TableCell specialityCell = new TableCell(); TableCell appointmentDateCell = new TableCell(); TableCell actionsCell = new TableCell(); //appointment date/time DateTime appointmentDate = userAppointment.AppointmentDate; DoctorsAndSpeciality docAndSpecs = _dc.DoctorsAndSpecialities.FirstOrDefault(d => d.ID == userAppointment.DoctorAndSpecialityID); // Doctor name Doctor doctorsName = _dc.Doctors.FirstOrDefault(d => d.ID == docAndSpecs.DoctorsID); //Speciality Speciality specialityName = _dc.Specialities.FirstOrDefault(d => d.ID == docAndSpecs.SpecialityID); countNumber.Text = count.ToString(); doctorCell.Text = doctorsName.FirstName.ToString() + " " + doctorsName.LastName.ToString(); specialityCell.Text = specialityName.SpecialityName.ToString(); appointmentDateCell.Text = appointmentDate.ToString(); actionsCell.Controls.Add(btnEdit); DateTime now = DateTime.Now; if (appointmentDate > now) { actionsCell.Controls.Add(btnDelete); } row.Cells.Add(countNumber); row.Cells.Add(doctorCell); row.Cells.Add(specialityCell); row.Cells.Add(appointmentDateCell); row.Cells.Add(actionsCell); AppointmentsTable.Rows.Add(row); count++; } } } else { Response.Redirect("Index.aspx"); } }