Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,CategoryId,ProductName,Price,ProductDescription")] Product product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "Name", product.CategoryId);
            return(View(product));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description")] Tag tag)
        {
            if (id != tag.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tag);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TagExists(tag.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
Пример #3
0
 public void DeleteAllProductOrders(Product delProduct)
 {
     foreach (var order in _ctx.Orders.Where(o => o.Product.Id == delProduct.Id))
     {
         order.Product = null;
         _ctx.Update(order);
     }
     _ctx.SaveChanges();
 }