/// <summary> /// Update record of product with new details /// </summary> /// <returns></returns> public async Task <IActionResult> OnPost(BlobViewModel BlobVM) { var idProduct = Request.Form["product"]; int productid = Convert.ToInt32(idProduct); Product product = await _context.GetItemByIDAsync(productid) ?? new Product(); string formName = Request.Form["name"]; product.Name = formName; string formSku = Request.Form["sku"]; product.Sku = Product.Sku; var formPrice = Request.Form["price"]; decimal price = Convert.ToDecimal(formPrice); product.Price = Product.Price; string formDescription = Request.Form["description"]; product.Description = Product.Description; string formImage = Request.Form["image"]; if (productid == 0) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await BlobVM.Image.CopyToAsync(stream); }; var container = await _blob.GetContainer("products"); // upload the image _blob.UploadFile(container, BlobVM.Image.FileName, filePath); CloudBlob blob = await _blob.GetBlob(BlobVM.Image.FileName, container.Name); string URL = blob.Uri.ToString(); product.Image = URL; await _context.CreateItem(product); } else { await _context.UpdateItemAsync(productid); } return(RedirectToPage("/ProductManager")); }
public ActionResult Blob(RepositoryNavigationRequest request) { var tree = GetTreeFromRequest(request); var node = tree.Node(request.Path); if (node == null) { throw new InvalidOperationException("Invalid path"); } var blob = node as Leaf; if (blob == null) { throw new InvalidOperationException("Path is not pointing to a tree."); } var viewModel = new BlobViewModel(Repository, request, blob) { FormattedData = _hightlightingService.GenerateHtml(blob.Data, blob.Path, null) }; return View(viewModel); }