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);
            }
        }
示例#2
0
        public FileContentResult GetImage(int id)
        {
            ImgObj site = db.ImgObjs.Find(id);


            if (site != null)
            {
                return(File(site.ImageData, site.FileContentType));
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        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
            }));
        }
示例#4
0
 public bool Update(ImgObj site)
 {
     db.Entry(site).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(true);
 }
示例#5
0
 public bool Delete(ImgObj site)
 {
     db.ImgObjs.Remove(site);
     return(true);
 }
示例#6
0
 public int AddImgObj(ImgObj obj)
 {
     db.ImgObjs.Add(obj);
     db.SaveChanges();
     return(0);
 }