public ActionResult Index(Movie movieToAdd, HttpPostedFileBase file) { try { //var fileName = Path.GetFileName(file.FileName); //var path = Path.Combine(Server.MapPath("~/Images"), fileName); //file.SaveAs(path); //movieToAdd.ImageName = file.FileName; // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("fsrimages"); container.CreateIfNotExists(); container.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName); // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = file.InputStream) { blockBlob.UploadFromStream(fileStream); } movieToAdd.ImageName = blockBlob.Uri.AbsoluteUri; _repo.AddMovie(movieToAdd); return(RedirectToAction("Index")); } catch (Exception ex) { return(RedirectToAction("Index", new { Error = ex.Message })); } }
public bool AddMovie(Movie movieToAdd) { return(_repo.AddMovie(movieToAdd)); }