Beispiel #1
0
        /// <summary>
        /// POST: /Admin
        /// updates existing inventory product in inventory or creates a new one
        /// </summary>
        /// <returns> reloads Admin page </returns>
        public async Task <IActionResult> OnPost()
        {
            Product query = await _inv.GetOneByIdAsync(Product.ID);

            Product.ID = 0;

            if (Image != null)
            {
                // do all the blob stuff
                // 1. make a filepath
                var filePath = Path.GetTempFileName();
                // 2. open stream
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await Image.CopyToAsync(stream);
                }
                // 3. get container and blob
                var container = await ImageBlob.GetContainer("products");

                CloudBlob blob = await ImageBlob.GetBlob(Image.FileName, container.Name);

                // 4. upload image
                ImageBlob.UploadFile(container, Image.FileName, filePath);
                Product.Image = blob.Uri.ToString();
            }

            if (query == null || query.ID == 0)
            {
                await _inv.CreateAsync(Product);
            }
            else
            {
                query.Sku         = Product.Sku;
                query.Name        = Product.Name;
                query.Price       = Product.Price;
                query.QtyAvail    = Product.QtyAvail;
                query.Description = Product.Description;
                query.Meaty       = Product.Meaty;
                query.Category    = Product.Category;
                query.Image       = Product.Image;
                await _inv.UpdateAsync(query);
            }
            CurrentInventory = await _inv.GetAllAsync();

            return(RedirectToPage("../Admin/Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPost()
        {
            Post query = await _post.GetOnePost(ID.GetValueOrDefault());

            if (query == null)
            {
                query        = new Post();
                query.UserID = Post.UserID;
            }

            query.Caption = (Post.Caption != null) ? Post.Caption : query.Caption;

            if (Image != null)
            {
                // do all the blob stuff
                // 1. make a filepath
                var filePath = Path.GetTempFileName();
                // 2. open stream
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await Image.CopyToAsync(stream);
                }
                // 3. get container and blob
                var container = await ImageBlob.GetContainer("userpics");

                CloudBlob blob = await ImageBlob.GetBlob(Image.FileName, container.Name);

                // 4. upload image
                ImageBlob.UploadFile(container, Image.FileName, filePath);
                query.Photo = blob.Uri.ToString();
            }

            if (query.ID == 0)
            {
                await _post.MakePost(query);
            }
            else
            {
                await _post.EditPost(query);
            }

            return(RedirectToPage("../Index"));
        }