コード例 #1
0
        public bool Upload(HttpPostedFileBase image, bool imageThumbnail, int productId)
        {
            var db = new ShoppingCartContext();

            if (image != null && image.ContentLength > 0)
            {
                var imageName = Path.GetFileName(image.FileName);
                var imageLocation = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/") + imageName);
                image.SaveAs(imageLocation);

                var imageUploadService = new ImageUploadLogic();
                var imagePath = "~/Images/" + imageName; //relative path for src
                imageUploadService.addImageDBRecord(imagePath, imageName, imageThumbnail, productId);

                return true;
            }
            else
                return false;
        }
コード例 #2
0
        public void addImageDBRecord(string imagePath, string imageName, bool imageThumbnail, int productId)
        {
            var imageUploader = new ImageUploadLogic();
            var newImage = new Image
            {
                ImageID = db.Images.Count() + 1,
                ImageTitle = imageName,
                ImagePath = imagePath,
                IsImageThumbnail = imageThumbnail,
                ProductId = productId,
            };
            db.Images.Add(newImage);
            db.SaveChanges();

            if (imageThumbnail)
            {
                var product = db.Products.Find(productId);
                product.ThumbnailImagePath = imagePath;
                db.SaveChanges();
            }
        }
コード例 #3
0
        public bool Upload(HttpPostedFileBase image, bool imageThumbnail, int productId)
        {
            var db = new ShoppingCartContext();

            if (image != null && image.ContentLength > 0)
            {
                var imageName     = Path.GetFileName(image.FileName);
                var imageLocation = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/") + imageName);
                image.SaveAs(imageLocation);

                var imageUploadService = new ImageUploadLogic();
                var imagePath          = "~/Images/" + imageName; //relative path for src
                imageUploadService.addImageDBRecord(imagePath, imageName, imageThumbnail, productId);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public void addImageDBRecord(string imagePath, string imageName, bool imageThumbnail, int productId)
        {
            var imageUploader = new ImageUploadLogic();
            var newImage      = new Image
            {
                ImageID          = db.Images.Count() + 1,
                ImageTitle       = imageName,
                ImagePath        = imagePath,
                IsImageThumbnail = imageThumbnail,
                ProductId        = productId,
            };

            db.Images.Add(newImage);
            db.SaveChanges();

            if (imageThumbnail)
            {
                var product = db.Products.Find(productId);
                product.ThumbnailImagePath = imagePath;
                db.SaveChanges();
            }
        }
コード例 #5
0
        public ActionResult ImageUpload(ImageUploadVM imageFile)
        {
            var imageUploadService = new ImageUploadLogic();

            if (imageUploadService.Upload(imageFile.Image, imageFile.ImageThumbnail, imageFile.ProductId))
            {
                ViewBag.Message = "Upload successful";
                return RedirectToAction("ProductDetails", "StoreManager", new { id = imageFile.ProductId });
            }
            else
            {
                ViewBag.Message = "Upload failed";
                return RedirectToAction("Upload");
            }
        }