Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Nombre,FechaApertura")] Tienda tienda)
        {
            if (id != tienda.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tienda);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TiendaExists(tienda.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tienda));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Color color)
        {
            if (id != color.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(color);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ColorExists(color.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(color));
        }
 /// <summary>
 /// updates a given basket item
 /// </summary>
 /// <param name="id">selects the item in the basket</param>
 /// <param name="basketItems">updates obj with a newly created obj with updates</param>
 /// <returns>update</returns>
 public async Task UpdateBasketItem(int id, [Bind("ID,BasketID,ProductID,Product,Quantity,LineItemAmount")] BasketItems basketItems)
 {
     try
     {
         _context.Update(basketItems);
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int[] Sizes, int id, Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);

                    var currentSizes = _context.ProductSizes.Where(x => x.ProductId == id);
                    var newSizes     = Sizes.Select(x => new ProductSizes {
                        ProductId = id, SizeId = x
                    });
                    _context.UpdateManyToMany(currentSizes, newSizes, x => x.SizeId);


                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            ViewData["ColorId"]    = new SelectList(_context.Colors, "Id", "Id", product.ColorId);
            ViewData["GenderId"]   = new SelectList(_context.Genders, "Id", "Id", product.GenderId);
            return(View(product));
        }