예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            ProductGalary productgalary = db.ProductGalaries.Find(id);

            db.ProductGalaries.Remove(productgalary);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult Edit(ProductGalary productgalary)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productgalary).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productgalary));
 }
예제 #3
0
        //
        // GET: /Admin/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ProductGalary productgalary = db.ProductGalaries.Find(id);

            if (productgalary == null)
            {
                return(HttpNotFound());
            }
            return(View(productgalary));
        }
예제 #4
0
        public ActionResult Upload(ProductGalary IG)
        {
            if (IG.File.ContentLength > (2 * 1024 * 1024))
            {
                ModelState.AddModelError("CustomError", "File size must be less than 2MB");
                return(View(IG));
            }

            if (!(IG.File.ContentType == "image/jpeg" || IG.File.ContentType == "image/gif"))
            {
                ModelState.AddModelError("CustomError", "File type must be jpg or gif");
                return(View());
            }

            IG.Model       = IG.Model;
            IG.Brand       = IG.Brand;
            IG.Description = IG.Description;
            IG.Price       = IG.Price;


            IG.FileName  = IG.File.FileName;
            IG.ImageSize = IG.File.ContentLength;


            byte[] data = new byte[IG.File.ContentLength];
            IG.File.InputStream.Read(data, 0, IG.File.ContentLength);

            IG.ImageData = data;

            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                dc.ProductGalaries.Add(IG);
                dc.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }