Beispiel #1
0
        public Task SaveUserCartAsync(UserCart userCart)
        {
            var db           = this.mux.GetDatabase();
            var userCartData = UserCartData.FromUserCart(userCart);
            var key          = GetKey(userCartData.UserId);

            return(db.StringSetAsync(key, JsonConvert.SerializeObject(userCartData)));
        }
Beispiel #2
0
#pragma warning restore S4004 // Collection properties should be readonly

        public static UserCartData FromUserCart(UserCart cart)
        {
            var cartData = new UserCartData
            {
                UserId    = cart.UserId,
                CartItems = new Dictionary <int, int>()
            };

            foreach (var item in cart.Items)
            {
                cartData.CartItems.Add(item.Key, item.Value.Quantity);
            }

            return(cartData);
        }