Beispiel #1
0
        public ActionResult Update(FoodArea.Models.Food food, HttpPostedFileBase Foodpicture)
        {
            if (Foodpicture != null)
            {
                string strPath = Request.PhysicalApplicationPath + @"Foodpicture\" + Foodpicture.FileName;
                Foodpicture.SaveAs(strPath);

                var    imgSize = Foodpicture.ContentLength;
                byte[] imgByte = new byte[imgSize];
                Foodpicture.InputStream.Read(imgByte, 0, imgSize);

                food.Foodpicture = Foodpicture.FileName;
                food.BytesImage  = imgByte;
            }
            db.Entry(food).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            ViewBag.datas = db.FoodCategory.ToList();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Create(FoodArea.Models.Food food, HttpPostedFileBase Foodpicture)
        {
            if (Foodpicture != null)
            {
                string strPath = Request.PhysicalApplicationPath + Foodpicture.FileName;
                Foodpicture.SaveAs(strPath);

                var    imgSize = Foodpicture.ContentLength;
                byte[] imgByte = new byte[imgSize];
                Foodpicture.InputStream.Read(imgByte, 0, imgSize);

                food.Foodpicture = Foodpicture.FileName;
                food.BytesImage  = imgByte;

                db.Food.Add(food);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.message = "請選擇圖片";
            ViewBag.datas   = db.FoodCategory.ToList();
            return(View());
        }
Beispiel #3
0
 public ActionResult GetImage(int id = 1)
 {
     FoodArea.Models.Food food = db.Food.Find(id);
     byte[] img = food.BytesImage;
     return(File(img, "image/jpeg"));
 }