예제 #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);
        }