Beispiel #1
0
        public ActionResult Edit(ImageUpload photo)
        {
            var photoOriginal = db.Images.Find(photo.ImageId);

            if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
            {
                HttpPostedFileBase file = Request.Files[0];
                Int32 length = file.ContentLength;
                photo.ContentType = file.ContentType;
                byte[] tempImage = new byte[length];
                file.InputStream.Read(tempImage, 0, length);
                photo.ImageData = tempImage;
            }
            else
            {
                photo.ImageData = photoOriginal.ImageData;
                photo.ContentType = photoOriginal.ContentType;
            }

            //db.Entry(photo).State = EntityState.Modified;
            db.Entry(photoOriginal).CurrentValues.SetValues(photo);
            db.SaveChanges();

            return RedirectToAction("Index");
        }
Beispiel #2
0
        public ActionResult Upload(ImageUpload photo)
        {
            HttpPostedFileBase file = Request.Files[0];
            Int32 length = file.ContentLength;
            photo.ContentType = file.ContentType;
            byte[] tempImage = new byte[length];
            file.InputStream.Read(tempImage, 0, length);
            photo.ImageData = tempImage;

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

            return RedirectToAction("Index");
        }