Example #1
0
        public ActionResult DeleteDish(int dishID)
        {
            try
            {
                DishTableAdapter DishAdapter = new DishTableAdapter();
                DataTable DishData = DishAdapter.GetDataByDishID(dishID);
                int test = DishAdapter.Delete(dishID);
                if (!string.IsNullOrEmpty(DishData.Rows[0]["Image"].ToString()))
                {
                    var deleteFilePath = AppDomain.CurrentDomain.BaseDirectory + DishData.Rows[0]["Image"].ToString();
                    System.IO.File.Delete(deleteFilePath);
                }
                Session["deleteDish"] = "Xóa thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["deleteDish"] = "Xóa thất bại! Món ăn đang được sử dụng.";
            }

            return RedirectToAction("ListDish", "Dish");
        }