public CartCheckedOut(ShoppingCart cart)
        {
            Id = cart.Id;

            var items = from line in cart.Lines
                group line by line.ProductId
                into lines
                select new {productId = lines.Key, quantity = lines.Sum(x => x.Quantity)};

            Items = items.ToDictionary(x => x.productId, x => (uint) x.quantity);
        }
        protected IHttpActionResult ShoppingCart(ShoppingCart cart, string error = null)
        {
            var response = new ShoppingCartResponse(cart, Url, error);

            AddLink(new HttpMethod("PATCH"), "add-items", response.Resource, "add-items", null);

            if (cart.Lines.Any())
                AddLink(HttpMethod.Post, "checkout", response.Resource, "CO", null);

            if (response.Error != null)
                LogResponseError(response.Error);

            return Ok(response);
        }
        async Task IShoppingCarts.SaveCartAsync(ShoppingCart cart)
        {
            var json = JsonConvert.SerializeObject(cart);

            store.AddOrUpdate(cart.Id, json, (id, s) => json);
        }
 public Item(ShoppingCart.Line line, UrlHelper urlHelper)
 {
     Product = new ResourceReference(urlHelper.GetProductDetailsUri(line.ProductId), line.ProductName);
     Quantity = line.Quantity;
 }
 private Item Map(ShoppingCart.Line line)
 {
     return new Item(line, urlHelper);
 }
 public ShoppingCartState(ShoppingCart cart, UrlHelper urlHelper)
 {
     this.urlHelper = urlHelper;
     Id = cart.Id;
     Items = Map(cart.Lines);
 }
 private string GetStorageId(ShoppingCart cart)
 {
     return GetStorageId(cart.Id);
 }
 public Task SaveCartAsync(ShoppingCart cart)
 {
     return storage.SaveAsync(GetStorageId(cart), cart);
 }