public ActionResult AddOrEdit(BKRY_ITEMS bkt, HttpPostedFileBase file)
 {
     byte[] buf = null;
     if (file != null && file.ContentLength > 0)
     {
         buf = new byte[file.ContentLength];
         file.InputStream.Read(buf, 0, buf.Length);
         bkt.image = buf;
     }
     bkt.insert_by  = Session != null && Session["UserName"] != null ? Session["UserName"].ToString() : "";
     bkt.add_date   = DateTime.Now;
     bkt.categoryId = Convert.ToInt64(Request.Form["categoryname"] != "" ? Request.Form["categoryname"] : "0");
     using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities())
     {
         if (bkt.Id == 0)
         {
             db.BKRY_ITEMS.Add(bkt);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             db.Entry(bkt).State = EntityState.Modified;
             try
             {
                 db.SaveChanges();
             }
             catch (DbEntityValidationException e)
             {
                 throw e;
             }
             return(RedirectToAction("Index"));
         }
     }
 }
 public ActionResult Delete(int id)
 {
     using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities())
     {
         BKRY_ITEMS emp = db.BKRY_ITEMS.Where(x => x.Id == id).FirstOrDefault <BKRY_ITEMS>();
         db.BKRY_ITEMS.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
示例#3
0
        public ActionResult getImage2(int id)
        {
            BKRY_ITEMS obj = null;

            obj = db.BKRY_ITEMS.Where(x => x.Id == id).ToList().FirstOrDefault();
            if (obj == null || obj.image == null)
            {
                return(null);
            }
            return(File(obj.image, "image/jpeg")); // Might need to adjust the content type based on your actual image type
        }