public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] InventoryItemCategory inventoryItemCategory)
        {
            if (id != inventoryItemCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(inventoryItemCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InventoryItemCategoryExists(inventoryItemCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(inventoryItemCategory));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Price,PrimaryPhotoId,UnitOfMeasureId,InventoryItemCategoryId")] InventoryItem inventoryItem)
        {
            if (id != inventoryItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(inventoryItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InventoryItemExists(inventoryItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InventoryItemCategoryId"] = new SelectList(_context.InventoryItemCategories, "Id", "Name", inventoryItem.InventoryItemCategoryId);
            ViewData["PrimaryPhotoId"]          = new SelectList(_context.InventoryItemPhotos, "Id", "Url", inventoryItem.PrimaryPhotoId);
            ViewData["UnitOfMeasureId"]         = new SelectList(_context.UnitsOfMeasure, "Id", "SingularName", inventoryItem.UnitOfMeasureId);
            return(View(inventoryItem));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Content,ProductId,IdentityUserId")] UserComment userComment)
        {
            if (id != userComment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserCommentExists(userComment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(Redirect("/home"));
            }
            ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", userComment.IdentityUserId);
            ViewData["ProductId"]      = new SelectList(_context.Products, "Id", "Id", userComment.ProductId);
            return(View(userComment));
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SingularName,PluralName")] UnitOfMeasure unitOfMeasure)
        {
            if (id != unitOfMeasure.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(unitOfMeasure);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UnitOfMeasureExists(unitOfMeasure.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(unitOfMeasure));
        }
Example #5
0
        public IActionResult GenerateProduct(Product product)
        {
            WebClient           webClient = new WebClient();
            StandardApiResponse imgResp   = api.callStandardApi("text2img", new { text = product.Name });
            StandardApiResponse descResp  = api.callStandardApi("text-generator", new { text = product.Name });

            Product newProduct = new Product(product.Name, descResp.output.ToString());

            context.Products.Add(newProduct);
            context.SaveChanges();
            newProduct.ImageURL = "/image/" + newProduct.Id + ".jpg";
            context.Update(newProduct);
            context.SaveChanges();

            webClient.DownloadFile(imgResp.output_url, "wwwroot/Image/" + newProduct.Id + ".jpg");

            return(Redirect("/product/" + newProduct.Id));
        }