public bool AddToWishList(Guid custid, AddWishListProductModel model) { if (model != null) { if (!ModelState.IsValid) throw ApiHelpers.ServerError(ModelState); var queryClient = _clientFactory.GetCustomersQueryServiceClient(); //REVIEW:Per Kevin: we persist to Favorites for wishlist and not wishlist. //But we must defensively check both lists before adding... var favorites = queryClient.GetFavoriteProducts(custid) ?? new ProductListItem[0]; var wishList = queryClient.GetWishlist(custid) ?? new ProductListItem[0]; var result = wishList.Concat(favorites).GroupBy(p => p.ProductId).Select(g => MapProduct(g.First())); if (!result.Any(p => p.id.Equals(model.ProductId))) { var commandClient = _clientFactory.GetCommandServiceClient(); try { commandClient.Execute(new AddProductIdToFavorites { CustomerId = custid, ProductId = model.ProductId }); return true; } catch (CommandException cex) { throw ApiHelpers.ServerError(cex.Message, string.Join("\r\n", cex.Errors)); } } } return false; }
public bool RemoveFromWishList(Guid custid, AddWishListProductModel model) { if (model != null) { if (!ModelState.IsValid) throw ApiHelpers.ServerError(ModelState); var commandClient = _clientFactory.GetCommandServiceClient(); try { commandClient.Execute(new RemoveProductFromFavorites { CustomerId = custid, ProductId = model.ProductId }); return true; } catch (CommandException cex) { throw ApiHelpers.ServerError(cex.Message, string.Join("\r\n", cex.Errors)); } } return false; }