public FileContentResult GetImage(int productId) { ImgObj prod = imgRepository.ImgObjs .FirstOrDefault(p => p.ImgObjId == productId); if (prod != null) { return(File(prod.ImageData, prod.FileContentType)); } else { return(null); } }
public FileContentResult GetImage(int id) { ImgObj site = db.ImgObjs.Find(id); if (site != null) { return(File(site.ImageData, site.FileContentType)); } else { return(null); } }
public RedirectToRouteResult AddNewImageFolder([Bind(Include = "FileName, SiteIds")] ImageViewModel model, HttpPostedFileBase image = null) { if (ModelState.IsValid) { ImgObj img = new ImgObj { ImgObjId = model.ImageId, FileName = model.FileName, }; img.FileContentType = image.ContentType; img.ImageData = new byte[image.ContentLength]; image.InputStream.Read(img.ImageData, 0, image.ContentLength); if (model.SiteIds != null) { foreach (var id in model.SiteIds) { var siteId = int.Parse(id); var site = db.Sites.Find(siteId); try { img.Sites.Add(site); } catch (Exception ex) { return(RedirectToAction("Error", new HandleErrorInfo(ex, "Site", "Manager"))); } } } try { db.ImgObjs.Add(img); db.SaveChanges(); } catch (Exception ex) { return(RedirectToAction("Error", new HandleErrorInfo(ex, "Site", "Manager"))); } TempData["message"] = string.Format("{0} has been included.", img.FileName); return(RedirectToAction("Manager", new SiteViewModel { ReturnUrl = model.ReturnUrl })); } TempData["Errmessage"] = string.Format("Failure."); return(RedirectToAction("Manager", new SiteViewModel { ReturnUrl = model.ReturnUrl })); }
public bool Update(ImgObj site) { db.Entry(site).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); }
public bool Delete(ImgObj site) { db.ImgObjs.Remove(site); return(true); }
public int AddImgObj(ImgObj obj) { db.ImgObjs.Add(obj); db.SaveChanges(); return(0); }