public List<Disease> GetllDiseases() { List<Disease> diseases=new List<Disease>(); SqlConnection connection = new SqlConnection(connectionstring); string query = "SELECT * FROM Table_Disease"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Disease disease=new Disease(); disease.Id = int.Parse(reader["diesease_Id"].ToString()); disease.Name = reader["disease_Name"].ToString(); disease.Description = reader["disease_Description"].ToString(); disease.TreatmentProcedure = reader["disease_TreatmentProcedure"].ToString(); diseases.Add(disease); } return diseases; }
public int Insert(Disease disease) { SqlConnection connection =new SqlConnection(connectionstring); string query = "INSERT INTO Table_Disease VALUES('"+disease.Name+"','"+disease.Description+"','"+disease.TreatmentProcedure+"')"; SqlCommand command=new SqlCommand(query,connection); connection.Open(); int rowsAffected = command.ExecuteNonQuery(); connection.Close(); return rowsAffected; }
public string Insert(Disease disease) { if (disease.Name == "") { return "disease name is missing"; } else if (disease.Description == "") { return "disease description is missing"; } else if (disease.TreatmentProcedure == "") { return "disease treatment procedure is missing"; } else if (diseaseGateway.HasThisDiesesName(disease.Name)) { return "disease name already exists"; } else { int value = diseaseGateway.Insert(disease); if (value > 0) { return "Saved Successfully"; } else { return "Operation Failed"; } } }