コード例 #1
0
        public static CartPosition Create(Event ev, int quantity)
        {
            var basketPosition = new CartPosition {
                Event = ev, Quantity = quantity
            };

            return(basketPosition);
        }
コード例 #2
0
        public bool SetQuantity(int eventId, int quantity)
        {
            bool doesContainEvent = BasketPositions.Any(item => item.Event.Id == eventId);

            if (!doesContainEvent)
            {
                return(false);
            }

            CartPosition bp = BasketPositions.First(item => item.Event.Id == eventId);

            bp.Quantity = quantity;
            return(true);
        }
コード例 #3
0
        public void AddFewToBasket(Event Event, int quantity)
        {
            bool doesContainEvent = BasketPositions.Any(item => item.Event.Id == Event.Id);

            if (!doesContainEvent)
            {
                BasketPositions.Add(CartPosition.Create(Event, quantity));
            }
            else
            {
                CartPosition bp = BasketPositions.First(item => item.Event.Id == Event.Id);
                bp.Quantity += quantity;
            }
        }
コード例 #4
0
        public bool RemoveFromBasket(int eventId, int quantity)
        {
            bool doesContainEvent = BasketPositions.Any(item => item.Event.Id == eventId);

            if (doesContainEvent)
            {
                CartPosition bp = BasketPositions.First(item => item.Event.Id == eventId);
                if (bp.Quantity > quantity)
                {
                    bp.Quantity -= quantity;
                }
                else
                {
                    BasketPositions.Remove(bp);
                }

                return(true);
            }

            return(false);
        }