Exemplo n.º 1
0
        public async Task <ItemInCart> AddProduct(Item item, Cart cart, Guid?userId = null)
        {
            if (userId == null)
            {
                throw new Exception("Unauthorized, cant add Product to Cart");
            }

            foreach (var itemInCart in cart.CartItems)
            {
                if (itemInCart.ItemId == item.Id)
                {
                    return(await IncreaseQuantity(itemInCart.Id, userId)); // if product already in cart just increase amount
                }
            }

            var cartItem = new ItemInCart
            {
                UserId                          = userId.Value,
                ItemId                          = item.Id,
                CartId                          = cart.Id,
                ItemPrice                       = item.Price,
                Discount                        = item.Discount,
                ItemPriceWithDiscount           = item.PriceWithDiscount,
                ItemPriceWithoutVat             = item.Price - item.Price * 0.2m,
                ItemPriceWithoutVatWithDiscount =
                    item.Price - item.Price * 0.2m - (item.Price - item.Price * 0.2m) * item.Discount / 100,
                ItemAmount = 1,
            };

            cartItem.TotalPrice = cartItem.ItemAmount * cartItem.ItemPriceWithDiscount;
            var result = base.Add(cartItem);

            return(result);
        }
Exemplo n.º 2
0
        public void Test_Item_Special_Active()
        {
            BuildDataTest();

            ItemInCart item = new ItemInCart(Database_API.GetItem("Soup"), 1);

            item.SetSpecialValue(Database_API.GetSpecial("Soup"));

            Assert.AreEqual(2, item.GetPrice());
        }
Exemplo n.º 3
0
        public v2.ItemInCart Map(ItemInCart outObject)
        {
            var im = new v2.ItemInCart()
            {
                Id     = outObject.Id,
                CartId = outObject.CartId,
                ItemId = outObject.ItemId,
                Item   = ItemMapper.Map(outObject.Item !),
                ItemPriceWithDiscount  = outObject.ItemPriceWithDiscount,
                TotalPriceWithDiscount = outObject.TotalPriceWithDiscount,
                Amount = outObject.ItemAmount
            };

            return(im);
        }
    }