/// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Models.SpecialDishes model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SpecialDishes set ");
            strSql.Append("RestaurantId=@RestaurantId,");
            strSql.Append("DishesName=@DishesName,");
            strSql.Append("PhotoPath=@PhotoPath");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RestaurantId", SqlDbType.Int,        4),
                new SqlParameter("@DishesName",   SqlDbType.NVarChar, 100),
                new SqlParameter("@PhotoPath",    SqlDbType.NVarChar, 200),
                new SqlParameter("@ID",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RestaurantId;
            parameters[1].Value = model.DishesName;
            parameters[2].Value = model.PhotoPath;
            parameters[3].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Models.SpecialDishes model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SpecialDishes(");
            strSql.Append("RestaurantId,DishesName,PhotoPath)");
            strSql.Append(" values (");
            strSql.Append("@RestaurantId,@DishesName,@PhotoPath)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RestaurantId", SqlDbType.Int,        4),
                new SqlParameter("@DishesName",   SqlDbType.NVarChar, 100),
                new SqlParameter("@PhotoPath",    SqlDbType.NVarChar, 200)
            };
            parameters[0].Value = model.RestaurantId;
            parameters[1].Value = model.DishesName;
            parameters[2].Value = model.PhotoPath;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        public List <Models.SpecialDishes> DataTableToList(DataTable dt)
        {
            List <Models.SpecialDishes> modelList = new List <Models.SpecialDishes>();
            int rowCount = dt.Rows.Count;

            if (rowCount > 0)
            {
                Models.SpecialDishes model;
                for (int i = 0; i < rowCount; i++)
                {
                    model = new Models.SpecialDishes();
                    if (dt.Rows[i]["ID"] != null && dt.Rows[i]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[i]["ID"].ToString());
                    }
                    if (dt.Rows[i]["RestaurantId"] != null && dt.Rows[i]["RestaurantId"].ToString() != "")
                    {
                        model.RestaurantId = (int)dt.Rows[i]["RestaurantId"];
                    }
                    if (dt.Rows[i]["DishesName"] != null && dt.Rows[i]["DishesName"].ToString() != "")
                    {
                        model.DishesName = dt.Rows[i]["DishesName"].ToString();
                    }
                    if (dt.Rows[i]["PhotoPath"] != null && dt.Rows[i]["PhotoPath"].ToString() != "")
                    {
                        model.PhotoPath = dt.Rows[i]["PhotoPath"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
        public ActionResult SpecialDish(HttpPostedFileBase DishImage, Int64 DishID = 0, string DishName = null)
        {
            string userid = User.Identity.GetUserId();
            string Status = "";

            string productimg = null;

            productimg = "MenuImages/" + DishImage.FileName;

            Models.SpecialDishes pm = new Models.SpecialDishes();

            var Exist = db.SpecialDishes.Where(s => s.DishID == DishID).FirstOrDefault();

            if (Exist == null)
            {
                pm.DishImage = productimg;
                pm.DishName  = DishName;
                pm.CreatedOn = DateTime.Now;

                db.SpecialDishes.Add(pm);
                int i = db.SaveChanges();

                Status = "Succeeded";
                string path = Server.MapPath("~/MenuImages/");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                DishImage.SaveAs(path + DishImage.FileName);
            }
            else
            {
                Exist.DishImage = productimg;
                Exist.DishName  = DishName;
                Exist.CreatedOn = DateTime.Now;


                db.SaveChanges();

                Status = "Succeeded";
                string path = Server.MapPath("~/MenuImages/");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                DishImage.SaveAs(path + DishImage.FileName);
            }

            TempData["Example"] = Status;
            return(RedirectToAction("SpecialDish", "Admin", new { area = "Admin" }));
        }
        //--------------------------Special Dishes------------------------------

        public ActionResult SpecialDish(Int64 DishID = 0)
        {
            Models.SpecialDishes pm = new Models.SpecialDishes();

            if (DishID > 0)
            {
                var exist = db.SpecialDishes.Where(s => s.DishID == DishID).FirstOrDefault();
                pm.DishName    = exist.DishName;
                pm.DishID      = DishID;
                pm.DishImage   = exist.DishImage;
                ViewBag.DishID = DishID;
            }

            ViewData["SpecialDish"] = db.SpecialDishes.ToList();
            return(View(pm));
        }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Models.SpecialDishes DataRowToModel(DataRow row)
 {
     Models.SpecialDishes model = new Models.SpecialDishes();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["RestaurantId"] != null && row["RestaurantId"].ToString() != "")
         {
             model.RestaurantId = int.Parse(row["RestaurantId"].ToString());
         }
         if (row["DishesName"] != null)
         {
             model.DishesName = row["DishesName"].ToString();
         }
         if (row["PhotoPath"] != null)
         {
             model.PhotoPath = row["PhotoPath"].ToString();
         }
     }
     return(model);
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.SpecialDishes GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,RestaurantId,DishesName,PhotoPath from SpecialDishes ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Models.SpecialDishes model = new Models.SpecialDishes();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }