示例#1
0
        //Method to Delete a Drug from the database
        public bool DeleteDrug(Drug drug)
        {
            //Connect to database using the connection string from App.config
            //Using a 'using' block to terminate the connection after we're finished with it
            using (var connection =
                       new MySqlConnection(ConfigurationManager.ConnectionStrings["premierCare"].ConnectionString)) {
                //SQL code to delete the drug from the database
                const string sql = "DELETE FROM Drug WHERE drug_id = @drug_id";

                //Adding parameters to the code to prevent against SQL injection
                //Executing the SQL code with added parameters. Returns number of Rows affected
                var rowsAffected = connection.Execute(sql, new { drug_id = drug.drug_id });

                //A successful delete will affect at least 1 Row and will return true
                //An unsuccessful delete will return 0 and therefore return false
                return(rowsAffected > 0);
            }
        }
示例#2
0
        //Method to Insert a Drug into the database
        public bool CreateDrug(Drug drug)
        {
            //Connect to database using the connection string from App.config
            //Using a 'using' block to terminate the connection after we're finished with it
            using (var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["premierCare"].ConnectionString)) {
                //SQL code to insert the drug into the database
                const string sql = "INSERT INTO Drug(drug_name, cost) VALUES(@drug_name, @cost)";

                //Adding parameters to the code to prevent against SQL injection
                //Executing the SQL code with added parameters. Returns number of Rows affected
                var rowsAffected = connection.Execute(sql, new {
                    drug_name = drug.drug_name,
                    cost      = drug.cost
                });

                //A successful insert will affect at least 1 Row and will return true
                //An unsuccessful insert will return 0 and therefore return false
                return(rowsAffected > 0);
            }
        }
示例#3
0
 public bool UpdateDrug(Drug drug)
 {
     return(drugDAO.UpdateDrug(drug));
 }
示例#4
0
 public bool DeleteDrug(Drug drug)
 {
     return(drugDAO.DeleteDrug(drug));
 }
示例#5
0
 public bool CreateDrug(Drug drug)
 {
     return(drugDAO.CreateDrug(drug));
 }