Example #1
0
        public Result AddToFavorites(string userId, string productId)
        {
            var cart = _confirmUserCartExistedDomainService.GetUserCart(userId);

            if (cart.IsEmpty())
            {
                return(Result.Fail("当前购物车中并没有商品"));
            }

            var cartItem = cart.GetCartItem(productId);

            if (cartItem == null)
            {
                return(Result.Fail("该购物项已不存在"));
            }

            var favorites = DomainRegistry.FavoritesRepository().GetByUserId(userId) ?? new Favorites(userId, null);

            favorites.AddFavoritesItem(cartItem);
            DomainRegistry.FavoritesRepository().Save(favorites);
            return(Result.Success());
        }