public async Task <IActionResult> OnPost() { var gram = await _gram.FindGram(ID.GetValueOrDefault()) ?? new Gram(); gram.Name = Gram.Name; gram.Title = Gram.Title; if (Image != null) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } //Get Container var container = await BlobImage.GetContainer("gram"); //Upload the Image BlobImage.UploadFile(container, Image.FileName, filePath); CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name); //Update the Database image for the gram gram.URL = blob.Uri.ToString(); } //save await _gram.SaveAsync(gram); //rederect return(RedirectToPage("/Index", new { id = gram.ID })); }
public async Task <IActionResult> OnPost() { // Make the call to our DB with our ID. var post = await _post.GetSinglePost(ID.GetValueOrDefault()) ?? new Posts(); // set the data from the database to the new data post.Author = Post.Author; post.ImageURL = Post.ImageURL; post.Capture = Post.Capture; if (Image != null) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } //Get Container var container = await BlobImage.GetContainer("images"); //upload the image BlobImage.UploadFile(container, Image.FileName, filePath); CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name); //update the db image for the post post.ImageURL = blob.Uri.ToString(); } // Save the post in the database await _post.SaveAsync(post); return(RedirectToPage("/Grams/Index", new { id = post.ID })); }