public ActionResult UpdateWishList(List<LineItemUpdateModel> lineItems, string action) { var ch = new CartHelper(CartHelper.CartName); var helper = new CartHelper(CartHelper.WishListName); if (action == UserHelper.AddToCartAction) { //add all to cart foreach (var lineItem in lineItems) { var li = helper.LineItems.FirstOrDefault(item => item.LineItemId == lineItem.LineItemId); if (li == null) { continue; } var catalogItem = _catalogClient.GetItem(li.CatalogItemId); var parentItem = _catalogClient.GetItem(li.ParentCatalogItemId); ch.AddItem(catalogItem, parentItem, lineItem.Quantity, false); helper.Remove(li); // If wishlist is empty, remove it from the database if (helper.IsEmpty) { helper.Delete(); } } ch.SaveChanges(); } else { foreach (var lineItem in lineItems) { var li = helper.LineItems.FirstOrDefault(item => item.LineItemId == lineItem.LineItemId); if (li == null) { continue; } li.Comment = lineItem.Comment; li.Quantity = lineItem.Quantity; } } helper.SaveChanges(); return RedirectToAction("WishList"); }