Пример #1
0
        public async Task <RedirectToActionResult> EditItemIngredients(int id, IFormCollection collection)
        {
            var checkedIngredientIds = collection.Keys.Where(x => x.StartsWith("ingredient-"));
            var checkedIngredients   = checkedIngredientIds.Select(ingredientId =>
                                                                   _context.Ingredients.First(x => x.IngredientId == int.Parse(ingredientId.Remove(0, 11)))).ToList();

            var updatedCartItem = await _cartItemService.EditCartItemIngredients(checkedIngredients,
                                                                                 _cartService.GetCart().CartItems.First(ci => ci.CartItemId == id));

            _cartService.UpdateItemIngredients(updatedCartItem);

            return(RedirectToAction("Index"));
        }