public async Task <IActionResult> OnPost() { Product existingProduct = await _invManager.GetProductByID(ID.GetValueOrDefault()) ?? new Product(); if (Image != null) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } var container = await BlobImage.GetContainer("products"); BlobImage.UploadFile(container, Image.FileName, filePath); CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name); Product.ImgUrl = blob.Uri.ToString(); existingProduct.ImgUrl = Product.ImgUrl; } existingProduct.Name = Product.Name; existingProduct.Price = Product.Price; existingProduct.ReleaseDate = Product.ReleaseDate; existingProduct.SKU = Product.SKU; existingProduct.Generation = Product.Generation; existingProduct.Description = Product.Description; await _invManager.UpdateProduct(ID.GetValueOrDefault(), existingProduct); return(RedirectToPage("/Admin/Products/Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _productManager.GetProductByID((int)id); var container = await BlobImage.GetContainer("product-image-asset-blob"); string[] imageURIArray = Product.Image.Split("/"); string imageName = imageURIArray[imageURIArray.Length - 1]; CloudBlob image = await BlobImage.GetBlob(imageName, container.Name); if (image != null) { await image.DeleteAsync(); } if (Product != null) { await _productManager.DeleteProduct(Product); } return(RedirectToPage("./Index")); }
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 })); }