示例#1
0
        public ActionResult Upload(WebApplicationAzure.Models.Image image)
        {
            foreach (string item in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                if (file.ContentLength == 0)
                {
                    continue;
                }

                if (file.ContentLength > 0)
                {
                    image.Id   = new Random().Next();
                    image.Name = image.Id.ToString() + file.FileName;
                    CloudBlobContainer blobContainer = _blobServices.GetCloudBlobContainer();
                    CloudBlockBlob     blob          = blobContainer.GetBlockBlobReference(image.Name);
                    blob.UploadFromStream(file.InputStream);

                    image.ImagePath = blob.Uri.AbsoluteUri;
                }

                int newImageFlag = _imageService.AddNewImage(image);
            }

            return(RedirectToAction("Upload"));
        }
        public int AddNewImage(WebApplicationAzure.Models.Image image)
        {
            using (DataClassesImageDataContext db = new DataClassesImageDataContext())
            {
                TableImage newImage = new TableImage();
                newImage.Id          = image.Id;
                newImage.Name        = image.Name;
                newImage.Description = image.Description;
                newImage.ImagePath   = image.ImagePath;

                db.TableImages.InsertOnSubmit(newImage);
                db.SubmitChanges();
            }
            return(image.Id);
        }