Ejemplo n.º 1
0
 public ActionResult Delete(int id, Data.ViewModels.MealDataVM meal)
 {
     // meal parameter is empty. Im not sure how to send the values from the view to the controller propperly
     // So i use the id value to know which meal to delete. But It has to be possible to send the data
     // back to the controller through databinding.
     try
     {
         Data.MealsManager.DeleteMeal(id, meal);
         return(RedirectToAction("Meals"));
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        // the meal parameter is unused here bcause i couldn't figure out how to send the data back from the view to the controller.
        // It's not a must have though so i only delete the meal based of its ID.
        public static void DeleteMeal(int id, Data.ViewModels.MealDataVM meal)
        {
            string query = "DELETE FROM Meals WHERE MealID = @ID;";

            using (SQLiteConnection con = new SQLiteConnection(conString))
            {
                using (SQLiteCommand cmd = new SQLiteCommand(query, con))
                {
                    // sqlinjection proofing
                    cmd.Parameters.Add("@ID", System.Data.DbType.Int32);
                    cmd.Parameters["@ID"].Value = id;
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    con.Close();
                }
            }
        }