Esempio n. 1
0
        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"));
        }
Esempio n. 2
0
        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 }));
        }