示例#1
0
        public async Task <Result <Dictionary <Guid, Dictionary <ProductData, int> > > > EditShoppingCart(string username, List <Guid> products_removed, Dictionary <Guid, int> products_added, Dictionary <Guid, int> products_quan)
        {
            Result <ShoppingCart> res = await marketUsers.editShoppingCart(username, products_removed, products_added, products_quan);

            if (res.IsErr)
            {
                return(new Result <Dictionary <Guid, Dictionary <ProductData, int> > >(null, true, res.Mess));
            }

            var cart = (ShoppingCart)res.Ret;

            if (cart == null)
            {
                return(null);
            }

            var dataCart = new Dictionary <Guid, Dictionary <ProductData, int> >();

            foreach (ShoppingBasket basket in cart.ShoppingBaskets)
            {
                var products = new Dictionary <ProductData, int>();
                foreach (ProductInCart p in basket.GetDictionaryProductQuantity())
                {
                    products.Add(new ProductData(p.product), p.quantity);
                }
                dataCart.Add(basket.GetStore().GetId(), products);
            }
            return(new Result <Dictionary <Guid, Dictionary <ProductData, int> > >(dataCart, false, null));
        }