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,Price,Amount,ShoppingListId,UserId")] ShoppingListItemModel shoppingListItemModel) { if (id != shoppingListItemModel.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shoppingListItemModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingListItemModelExists(shoppingListItemModel.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ShoppingListId"] = new SelectList(_context.ShoppingLists, "id", "id", shoppingListItemModel.ShoppingListId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", shoppingListItemModel.UserId); return(View(shoppingListItemModel)); }
public async Task <IActionResult> Create([Bind("id,Name,Price,Amount,ShoppingListId,UserId")] ShoppingListItemModel shoppingListItemModel) { if (ModelState.IsValid) { _context.Add(shoppingListItemModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ShoppingListId"] = new SelectList(_context.ShoppingLists, "id", "id", shoppingListItemModel.ShoppingListId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", shoppingListItemModel.UserId); return(View(shoppingListItemModel)); }
public List <ShoppingListItemModel> GetItemsForShoppingList(Guid shoppingListId) { using var context = new HomeAppDbContext(myDbOptions); var items = new List <ShoppingListItemModel>(); var listItems = context.ShoppingListItems.Include(i => i.Product).Include(i => i.ItemInfos).ThenInclude(i => i.RecipeItem).ThenInclude(r => r.Recipe).Where(i => i.ShoppingList.Id == shoppingListId).ToList(); foreach (var i in listItems) { var newItem = new ShoppingListItemModel { Id = i.Id, ShoppingListId = shoppingListId, IsChecked = i.IsChecked, ProductId = i.Product.Id, ProductName = i.Product.Name, InfoItems = ConvertInfoItems(i.ItemInfos) }; items.Add(newItem); } return(items); }
public void AddProductToShoppingList(Guid listId, ShoppingListItemModel item) { throw new NotImplementedException(); }
public void AddItemToShoppingList(Guid listId, ShoppingListItemModel item) { myShoppingListDataAdapter.AddProductToShoppingList(listId, item); }