Beispiel #1
0
        public ActionResult Edit([Bind(Include = "ProductID,ProductName,Price,UnitsSold,TypeID,MakeID,Model,ProductStatusID,Description,ProductImage,IsFeatured")] Product product, HttpPostedFileBase productImage)
        {
            if (ModelState.IsValid)
            {
                #region File Edit
                string file = "noImage.png";

                if (productImage != null)
                {
                    // The user has uploaded a file to include for that specific book.
                    file = productImage.FileName;
                    // Check that the uploaded file extension matches accepted extensions
                    string   ext      = file.Substring(file.LastIndexOf('.'));
                    string[] goodExts = { ".jpg", ".jpeg", ".png", ".gif" };

                    // Check that the file extension is in our list of acceptable extensions AND check that the file size is 4MB MAX
                    if (goodExts.Contains(ext.ToLower()) && productImage.ContentLength <= 5242880)
                    {
                        // Create a new file name (using a GUID)
                        file = Guid.NewGuid() + ext;

                        #region Resize Image
                        // This informs the program to save the image to this location in our file structure.
                        string savePath = Server.MapPath("~/Content/images/");

                        Image convertedImage = Image.FromStream(productImage.InputStream);

                        int maxImageSize = 400;

                        int maxThumbSize = 100;

                        ImageServices.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize);
                        #endregion

                        // The code below will delete the old image from the file structure.
                        if (product.ProductImage != null && product.ProductImage != "noImage.png")
                        {
                            string path = Server.MapPath("~/Content/images/");
                            ImageServices.Delete(path, product.ProductImage);
                        }
                    }
                }

                // No matter what, update the photoUrl with the value of the file variable
                product.ProductImage = file;
                #endregion
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.MakeID          = new SelectList(db.ProductMakes, "MakeID", "MakeName", product.MakeID);
            ViewBag.ProductStatusID = new SelectList(db.ProductStatuses, "ProductStatusID", "ProductStatusName", product.ProductStatusID);
            ViewBag.TypeID          = new SelectList(db.ProductTypes, "TypeID", "TypeName", product.TypeID);
            return(View(product));
        }
Beispiel #2
0
        public ActionResult DeleteConfirmed(Image image)
        {
            ImageServices service = new ImageServices();

            if (!service.Delete(image.ImageId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(RedirectToAction("GetUserPage", "Users", new { page = image.Page }));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            //Pet pet = db.Pets.Find(id);
            //db.Pets.Remove(pet);
            //db.SaveChanges();
            Pet pet = uow.PetRepository.Find(id);

            string pathOfSavedImage = Server.MapPath("~/Content/Images/Pets/");
            Pet    petPhotoDestroy  = uow.PetRepository.Find(id);

            ImageServices.Delete(pathOfSavedImage, petPhotoDestroy.PetPhoto);


            uow.PetRepository.Remove(pet);
            uow.Save();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            //Product product = db.Products.Find(id);
            Product product = uow.ProductRepository.Find(id);

            #region Delete Associated BookImage If it exists (Use ImageService)
            //Set path on server where images are stored
            string path = Server.MapPath("~/Content/Images/_BoxCovers/");
            ImageServices.Delete(path, product.ProductImage);
            #endregion


            //db.Products.Remove(product);
            //db.SaveChanges();

            uow.ProductRepository.Remove(product);
            uow.Save();
            return(RedirectToAction("Index"));
        }