Example #1
0
        public IHttpActionResult PutProImage(int id, ProImage proImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != proImage.img_id)
            {
                return(BadRequest());
            }

            db.Entry(proImage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public static bool addProduct(ModelView.ProductView item, HttpPostedFileBase picture)
        {
            try
            {
                db = new ShopOnlineEntities();
                Product p = new Product
                {
                    name        = item.name,
                    price       = item.price,
                    stock       = item.stock,
                    IDC         = item.IDC,
                    description = item.description,
                    StatusProd  = 1
                };
                db.Products.Add(p);
                db.SaveChanges();
                ProImage img = new ProImage
                {
                    Name      = picture.FileName,
                    IDP       = p.id,
                    StatusIMG = 1
                };
                db.ProImages.Add(img);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(false);
        }
Example #3
0
        public static bool AddNewImage(ModelView.ProImageView item)
        {
            ShopOnlineEntities en = new ShopOnlineEntities();
            ProImage           pi = new ProImage {
                Name = item.Name, IDP = item.IDP, StatusIMG = item.StatusIMG
            };

            en.ProImages.Add(pi);
            return(en.SaveChanges() > 0);
        }
Example #4
0
        public IHttpActionResult GetProImage(int id)
        {
            ProImage proImage = db.ProImages.Find(id);

            if (proImage == null)
            {
                return(NotFound());
            }

            return(Ok(proImage));
        }
Example #5
0
        public IHttpActionResult DeleteProImage(int id)
        {
            ProImage proImage = db.ProImages.Find(id);

            if (proImage == null)
            {
                return(NotFound());
            }

            db.ProImages.Remove(proImage);
            db.SaveChanges();

            return(Ok(proImage));
        }
Example #6
0
        // POST: api/ProImages
        public String POST()
        {
            int counter = 0;

            //COLLECTING FILES------->
            System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
            string   url     = HttpContext.Current.Request.Url.AbsoluteUri;
            ProImage picfun  = new ProImage();
            var      prod_id = db.Products.Select(i => i).ToArray().LastOrDefault();
            String   Status  = "";

            for (int i = 0; i < files.Count; i++)
            {
                //GET THE POSTED FILES------>
                System.Web.HttpPostedFile file = files[i];

                string fileName = new FileInfo(file.FileName).Name;


                if (file.ContentLength > 0)
                {
                    Guid id = Guid.NewGuid();

                    string modifiedFileName = id.ToString() + "_" + fileName;

                    byte[] imageb = new byte[file.ContentLength];
                    file.InputStream.Read(imageb, 0, file.ContentLength);
                    picfun.img_id  = new Random().Next();
                    picfun.Image   = imageb;
                    picfun.prod_id = Convert.ToInt32(prod_id.prod_id.ToString());
                    picfun.Image   = imageb;
                    db.ProImages.Add(picfun);
                    db.SaveChanges();
                    counter++;
                }
            }

            if (counter > 0)
            {
                return(Status);
            }
            return("Upload Failed");
        }
Example #7
0
 public static bool updateProduct(ModelView.ProductView item, HttpPostedFileBase picture)
 {
     db = new ShopOnlineEntities();
     try
     {
         Product p = db.Products.Find(item.id) as Product;
         p.name        = item.name;
         p.price       = item.price;
         p.stock       = item.stock;
         p.description = item.description;
         //p.StatusProd = item.StatusProd
         db.SaveChanges();
         ProImage pi = db.ProImages.Where(pix => pix.IDP == p.id).FirstOrDefault() as ProImage;
         pi.Name = picture.FileName;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }