public FileResult ProductCategoryImgage(int id)
 {
     ProductCategory category = new ProductCategory();
     category = db.ProductCategories.Find(id);
     return File(category.Picture, "image/jpg");
 }
 public ActionResult AddProductCategory(ProductCategory model, HttpPostedFileBase file)
 {
     if (file != null)
     {
         System.IO.Stream stream = file.InputStream;
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, (int)stream.Length);
         stream.Close();
         model.Picture = buffer;
         model.AddTime = DateTime.Now;
         db.ProductCategories.Add(model);
         db.SaveChanges();
         return Redirect("/Admin/ProductCategoryManager");
     }
     else
     {
         return Redirect("/Admin/AdminMessage?msg=你填写信息不正确,请重新填写!");
     }
 }
 public ActionResult ShowProductCategoryImg(int id)
 {
     ProductCategory category = new ProductCategory();
     category = db.ProductCategories.Find(id);
     return File(category.Picture, "image/jpg");
 }
 public ActionResult ProductCategoryEdit(ProductCategory model, HttpPostedFileBase file)
 {
     ProductCategory category = new ProductCategory();
     category = db.ProductCategories.Find(model.ID);
     category.Content = model.Content;
     category.FatherID = model.FatherID;
     category.Priority = model.Priority;
     if (file != null)
     {
         System.IO.Stream stream = file.InputStream;
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, (int)stream.Length);
         stream.Close();
         category.Picture = buffer;
     }
     db.SaveChanges();
     return Redirect("/Admin/ProductCategoryManager");
 }
        public ActionResult ProductCategoryEdit(int id)
        {
            ProductCategory category = new ProductCategory();
            category = db.ProductCategories.Find(id);

            List<ProductCategory> categories = new List<ProductCategory>();
            categories = db.ProductCategories.Where(pc => (pc.FatherID == null || pc.FatherID == 0) && pc.Belong == (ProductBelong)category.Belong).ToList();
            ViewBag.LastProductCategories = categories;
            return View(category);
        }
 public ActionResult ProductCategoryDelete(int id)
 {
     try
     {
         ProductCategory category = new ProductCategory();
         category = db.ProductCategories.Find(id);
         List<ProductCategory> categories = new List<ProductCategory>();
         categories = db.ProductCategories.Where(pc => pc.FatherID == id).ToList();
         foreach (var item in categories)
         {
             item.FatherID = 0;
         }
         db.ProductCategories.Remove(category);
         db.SaveChanges();
         return Content("ok");
     }
     catch
     {
         return Content("err");
     }
 }