Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Country")] Artist artist)
        {
            if (id != artist.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(artist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArtistExists(artist.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CartId")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"] = new SelectList(_context.Cart, "Id", "Id", customer.CartId);
            return(View(customer));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,CartId,ProductId")] CartItem cartItem)
        {
            if (id != cartItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cartItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CartItemExists(cartItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"]    = new SelectList(_context.Cart, "Id", "Id", cartItem.CartId);
            ViewData["ProductId"] = new SelectList(_context.Set <Product>(), "Id", "Name", cartItem.ProductId);
            return(View(cartItem));
        }
        // GET: Products/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.Product
                          .Include(p => p.Artist)
                          .Include(p => p.Category)
                          .FirstOrDefaultAsync(m => m.Id == id);

            if (product == null)
            {
                return(NotFound());
            }
            else
            {
                try
                {
                    // increase click when enter details and update database
                    product.Click = product.Click + 1;
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(View(product));
        }