Ejemplo n.º 1
0
        public void AddTicketToCart(CurrentExhibitionModel Exhibition, int quantity, string cartId)
        {
            TicketsInCart ticketincartEntity = _unitOfWork.TicketsInCartRepository.GetAll().ToList().Find(
                i => i.CartId == cartId && i.CurExhId == Exhibition.Id);

            var exh = _unitOfWork.ExhibitionRepository.Get(Exhibition.IdExh);

            if (ticketincartEntity != null)
            {
                ticketincartEntity.Quantity  += quantity;
                ticketincartEntity.TotalPrice = exh.Price * ticketincartEntity.Quantity;
                _unitOfWork.TicketsInCartRepository.Update(ticketincartEntity);
            }
            else
            {
                if (Exhibition.MaxTicketQuantity > 0)
                {
                    TicketInCartModel newItem = new TicketInCartModel()
                    {
                        CurExhId   = Exhibition.Id,
                        BuyDate    = DateTime.Now,
                        Quantity   = quantity,
                        CartId     = cartId,
                        TotalPrice = exh.Price * quantity
                    };

                    TicketsInCart newItemEntity = _mapper.Map <TicketsInCart>(newItem);
                    _unitOfWork.TicketsInCartRepository.Add(newItemEntity);
                    _unitOfWork.Save();
                }
            }

            CurrentExhibition ticketsForExh = _unitOfWork.CurrentExhibitionRepository.Get(Exhibition.Id);

            ticketsForExh.maxTicketQuantity -= quantity;
            _unitOfWork.CurrentExhibitionRepository.Update(ticketsForExh);

            _unitOfWork.Save();
        }
Ejemplo n.º 2
0
        public void RemoveTicketFromCart(int itemId, int curExhId)
        {
            TicketsInCart     itemEntity       = _unitOfWork.TicketsInCartRepository.Get(itemId);
            CurrentExhibition exhibitionEntity = _unitOfWork.CurrentExhibitionRepository.Get(curExhId);

            if (itemEntity.Quantity > 1)
            {
                itemEntity.Quantity--;
                itemEntity.TotalPrice = _unitOfWork.ExhibitionRepository.Get(exhibitionEntity.IdExh).Price *itemEntity.Quantity;
                _unitOfWork.TicketsInCartRepository.Update(itemEntity);
            }
            else if (itemEntity.Quantity == 1)
            {
                _unitOfWork.TicketsInCartRepository.Delete(itemEntity.Id);
            }

            CurrentExhibition ceEntity = _unitOfWork.CurrentExhibitionRepository.Get(curExhId);

            ceEntity.maxTicketQuantity++;
            _unitOfWork.CurrentExhibitionRepository.Update(ceEntity);

            _unitOfWork.Save();
        }