public HttpResponseMessage Post()
        {
            if (HttpContext.Current.Request.Files.Count == 0)
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];

            byte[] bytes;
            //int ID = 2;
            using (BinaryReader br = new BinaryReader(postedFile.InputStream))
            {
                bytes = br.ReadBytes(postedFile.ContentLength);
            }
            ProdImage p = new ProdImage()
            {
                //productID = id,
                //product_name = postedFile.FileName,
                photo = bytes
            };

            db.ProdImages.Add(p);
            db.SaveChanges();
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        public void UpdateSort(int id, int oldSort, int newSort)
        {
            var       curr   = this.Get(id);
            ProdImage image  = this.ProdImages.Where(x => x.ProductID == id).SingleOrDefault <ProdImage>(x => x.Sortindex == oldSort);
            ProdImage image2 = this.ProdImages.Where(x => x.ProductID == id).SingleOrDefault <ProdImage>(x => x.Sortindex == newSort);

            image.Sortindex  = newSort;
            image2.Sortindex = oldSort;
            db.SaveChanges();
        }
Exemplo n.º 3
0
        public void PhotoDel(ProdImage pimg)
        {
            var Prodimg  = db.ProdImages.SingleOrDefault(x => x.ID == pimg.ID);
            var dirPath  = HttpContext.Current.Server.MapPath("~/Content/Files/Product/" + pimg.ProductID + "/" + Prodimg.ImageMimeType);
            var dirPaths = HttpContext.Current.Server.MapPath("~/Content/Files/Product/" + pimg.ProductID + "/200x150" + "/" + Prodimg.ImageMimeType);

            filemanager.RemoveFile(dirPath);
            filemanager.RemoveFile(dirPaths);

            db.ProdImages.Remove(pimg);
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public int SavePhoto(HttpPostedFileBase file, int pid)
        {
            if (file.ContentLength > 4000000)
            {
                throw new HttpException();
            }

            int imagesCount = 0;
            var prodImg     = new ProdImage();

            prodImg.ProductID = pid;
            db.ProdImages.Add(prodImg);
            db.SaveChanges();
            prodImg.Sortindex = prodImg.ID;

            var dirPath  = HttpContext.Current.Server.MapPath("~/Content/Files/Product/" + pid);
            var dirPaths = HttpContext.Current.Server.MapPath("~/Content/Files/Product/" + pid + "/200x150");

            imagesCount = filemanager.CheckDirectory(dirPath);
            var rndName  = filemanager.GetRandomName(imagesCount);
            var filePath = Path.Combine(dirPath, rndName + Path.GetExtension(file.FileName));

            imagesCount = filemanager.CheckDirectory(dirPaths);
            var filePaths = Path.Combine(dirPaths, rndName + Path.GetExtension(file.FileName));
            var istream   = new WebImage(file.InputStream).Resize(761, 1101, true, true).Crop(1, 1).GetBytes();

            filemanager.WriteImage(istream, filePath);
            istream = new WebImage(istream).Resize(261, 361, false, true).Crop(1, 1).GetBytes();
            filemanager.WriteImage(istream, filePaths);

            prodImg.ImageMimeType = rndName + Path.GetExtension(file.FileName);

            db.SaveChanges();

            return(prodImg.ID);
        }