// UPDATE exisiting nahrung
 public int UpdateNahrung(long id, NahrungInput nahrung)
 {
     using (MySqlConnection conn = GetConnection())
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand("UPDATE nahrung SET Name = '" + nahrung.Name + "', Kilokalorien = '" + nahrung.Kilokalorien + "', TierID = '" + nahrung.TierID + "', ZooID = '" + nahrung.ZooID + "' WHERE ID = '" + id + "';", conn);
         return(cmd.ExecuteNonQuery());
     }
 }
 // CREATE new nahrung
 public int CreateNahrung(NahrungInput nahrung)
 {
     using (MySqlConnection conn = GetConnection())
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand("INSERT INTO nahrung (Name, Kilokalorien, TierID, ZooID) VALUES ('" + nahrung.Name + "', '" + nahrung.Kilokalorien + "', '" + nahrung.TierID + "', '" + nahrung.ZooID + "')", conn);
         return(cmd.ExecuteNonQuery());
     }
 }
Esempio n. 3
0
        public ActionResult <int> UpdateNahrung(long id, NahrungInput nahrung)
        {
            SQLConnectionNahrung t = new("server=localhost;port=3306;database=ZooDatenbank;user=root;password=root");

            if (t.UpdateNahrung(id, nahrung) == 1)
            {
                return(1);
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 4
0
        public ActionResult <NahrungInput> CreateNahrung(NahrungInput nahrung)
        {
            SQLConnectionNahrung t = new("server=localhost;port=3306;database=ZooDatenbank;user=root;password=root");

            if (t.CreateNahrung(nahrung) >= 1)
            {
                return(nahrung);
            }
            else
            {
                throw new Exception("didn't work");
            }
        }