public ActionResult <int> UpdateTier(long id, TierInput tier) { SQLConnectionTier t = new("server=localhost;port=3306;database=ZooDatenbank;user=root;password=root"); if (t.UpdateTier(id, tier) == 1) { return(1); } else { return(NotFound()); } }
public ActionResult <TierInput> CreateTier(TierInput tier) { SQLConnectionTier t = new("server=localhost;port=3306;database=ZooDatenbank;user=root;password=root"); if (t.CreateTier(tier) >= 1) { return(tier); } else { throw new Exception("didn't work"); } }
// UPDATE exisiting tier public int UpdateTier(long id, TierInput tier) { using (MySqlConnection conn = GetConnection()) { conn.Open(); int help = 0; if (tier.Vegetarier == true) { help = 1; } MySqlCommand cmd = new MySqlCommand("UPDATE tier SET ZooID = '" + tier.ZooID + "', Tierart = '" + tier.Tierart + "', Name = '" + tier.Name + "', Vegetarier = '" + help + "' WHERE ID = '" + id + "';", conn); return(cmd.ExecuteNonQuery()); } }
// CREATE new tier public int CreateTier(TierInput tier) { using (MySqlConnection conn = GetConnection()) { conn.Open(); int help = 0; if (tier.Vegetarier == true) { help = 1; } MySqlCommand cmd = new MySqlCommand("INSERT INTO tier (ZooID, Tierart, Name, Vegetarier) VALUES ('" + tier.ZooID + "', '" + tier.Tierart + "', '" + tier.Name + "', '" + help + "')", conn); return(cmd.ExecuteNonQuery()); } }