protected void saveButton_Click(object sender, EventArgs e)
 {
     Doctor aDoctor = new Doctor();
     aDoctor.DoctorName = doctorNameTextBox.Text;
     aDoctor.Degree = degreeTextBox.Text;
     aDoctor.Specialization = specializationTextBox.Text;
     int centerId =int.Parse( Session["centerId"].ToString());
     mesLabel.Text = doctorManager.SaveDoctor(aDoctor, centerId);
 }
        public string SaveDoctor(Doctor aDoctor, int centerId)
        {
            int value = doctorGateway.SaveDoctor(aDoctor, centerId); ;

            if (value > 0)
            {
                return "Doctor Has Been Saved";
            }
            else return "Failed";
        }
        public int SaveDoctor(Doctor aDoctor, int centerId)
        {
            string query = "INSERT INTO DoctorTBL VALUES('" +aDoctor.DoctorName + "','" + aDoctor.Degree + "','" + aDoctor.Specialization + "','"+centerId+"')";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            int rowAffected = command.ExecuteNonQuery();
            connection.Close();
            return rowAffected;
        }
        public bool IsDoctorExists(Doctor aDoctor)
        {
            bool exists = false;
            string query = "SELECT * FROM DoctorTBL WHERE DoctorName='" +aDoctor.DoctorName+ "'";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {

                exists = true;
            }
            reader.Close();
            connection.Close();
            return exists;
        }
 protected void saveButton_Click(object sender, EventArgs e)
 {
     Doctor aDoctor = new Doctor();
     aDoctor.DoctorName = doctorNameTextBox.Text;
     aDoctor.Degree = degreeTextBox.Text;
     aDoctor.Specialization = specializationTextBox.Text;
     if (doctorManager.IsDoctorExists(aDoctor))
     {
         mesLabel.Text = "";
         errorMegLabel.Text = "This doctor name already exists!";
     }
     else
     {
         errorMegLabel.Text = "";
         int centerId = int.Parse(Session["centerId"].ToString());
         mesLabel.Text = doctorManager.SaveDoctor(aDoctor, centerId);
         doctorNameTextBox.Text = "";
         degreeTextBox.Text = "";
         specializationTextBox.Text = "";
     }
 }
        public List<Doctor> GetAllDoctors(int centerId)
        {
            List<Doctor> doctorsList = new List<Doctor>();

            string query = "SELECT * FROM DoctorTBL WHERE CenterId='"+centerId+"'";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Doctor aDoctor = new Doctor();
                aDoctor.Id = int.Parse(reader["Id"].ToString());
                aDoctor.DoctorName = reader["DoctorName"].ToString();
                doctorsList.Add(aDoctor);
            }

            reader.Close();
            connection.Close();

            return doctorsList;
        }
 public bool IsDoctorExists(Doctor aDoctor)
 {
     return doctorGateway.IsDoctorExists(aDoctor);
 }