public async Task <IActionResult> Edit(int id, [Bind("Id,ListName,CreatingDate,Price,UserId")] ShopList shopList) { if (id != shopList.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shopList); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShopListExists(shopList.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(shopList)); }
public async Task <ShoppingListItemModel> Post([FromBody] ShoppingListItemModel value) { var shoppingList = await _context.ShoppingList.SingleOrDefaultAsync(m => m.Id == value.Id); if (shoppingList != null) { shoppingList.Item = value.Item; shoppingList.Quantity = value.Quantity; shoppingList.CategoryId = value.Category.Id; _context.Update(shoppingList); await _context.SaveChangesAsync(); } else { shoppingList = new ShoppingListItem() { Item = value.Item, Quantity = value.Quantity, CategoryId = value.Category.Id, WeekId = 1 }; _context.Add(shoppingList); await _context.SaveChangesAsync(); } var category = await _context.Category.SingleAsync(u => u.Id == shoppingList.CategoryId); return(Map(shoppingList, category)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Quantity,Price,AmountProduct")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,ShelfId,Warranty")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ShelfId"] = new SelectList(_context.Shelfs, "Id", "Id", product.ShelfId); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("iD,name")] Items items) { if (id != items.iD) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(items); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemsExists(items.iD)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(items)); }