public string Insert(Doctor doctor) { if (doctor.Name == "") { return "doctor name is missing"; } else if(doctor.Degree=="") { return "doctor's degree is missing"; } else if(doctor.Specialzation=="") { return "doctor's specialization is missing"; } else { int value = centerGateway.Insert(doctor); if (value > 0) { return "Saved Successfully"; } else { return "Operation Failed"; } } }
public int Insert(Doctor doctor) { SqlConnection connection = new SqlConnection(connectionstring); string query = "INSERT INTO Table_Doctor VALUES ('" + doctor.Name + "','" + doctor.Degree + "','" + doctor.Specialzation + "','"+doctor.CenterId+"')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowsAffected = command.ExecuteNonQuery(); connection.Close(); return rowsAffected; }
public List<Doctor> GetDoctorsList(int id) { List<Doctor> doctors=new List<Doctor>(); SqlConnection connection = new SqlConnection(connectionstring); string query = "SELECT * FROM Table_Doctor WHERE doctor_CenterId='"+id+"' "; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Doctor doctor=new Doctor(); doctor.Id = int.Parse(reader["doctor_Id"].ToString()); doctor.Name = reader["doctor_Name"].ToString(); doctors.Add(doctor); } reader.Close(); connection.Close(); return doctors; }