Exemplo n.º 1
0
        public IEnumerable <TicketDTO> GetUserTickets(string Id)
        {
            List <Ticket>    tickets    = _unit.TicketRepository.GetAllQueryable().Where(t => t.UserProfileId == Id).ToList();
            List <TicketDTO> ticketsDTO = new List <TicketDTO>();

            if (tickets.Count == 0)
            {
                return(ticketsDTO);
            }
            foreach (Ticket DataTicket in tickets)
            {
                if (DataTicket.Status == "Booked" && DateTime.Now > DataTicket.ReservationTimeEnd)
                {
                    DataTicket.Status        = "Free";
                    DataTicket.UserProfileId = null;
                }
                _unit.TicketRepository.Update(DataTicket);
            }
            _unit.Save();
            foreach (Ticket tick in tickets)
            {
                if (tick.Status != "Free")
                {
                    Session    session    = _unit.SessionRepository.Get(tick.SessionId);
                    SessionDTO sessionDTO = _mapper.Map <SessionDTO>(session);
                    TicketDTO  t          = _mapper.Map <TicketDTO>(tick);
                    t.Session = sessionDTO;
                    ticketsDTO.Add(t);
                }
            }
            return(ticketsDTO);
        }
Exemplo n.º 2
0
        public void CreateSession(SessionDTO sessionDTO)
        {
            Session       session = _mapper.Map <Session>(sessionDTO);
            List <Ticket> tickets = new List <Ticket>();

            session.Hall        = _unit.HallRepository.Get(session.HallId);
            session.Performance = _unit.PerformanceRepository.Get(session.PerformanceId);
            _unit.SessionRepository.Create(session);
            _unit.Save();
            List <Seat> seats = _unit.SeatRepository.GetAll().Where(p => p.HallId == session.HallId).ToList();

            for (int i = 1; i <= session.Hall.NumberOfSeats; i++)
            {
                Ticket ticket = new Ticket
                {
                    SeatId    = seats[0].Id,
                    Seat      = seats[0],
                    SessionId = session.Id,
                    Price     = (decimal)(seats[0].RowNumber * 1.2 + 100),
                    Status    = "Free"
                };
                tickets.Add(ticket);
                seats.RemoveAt(0);
                _unit.TicketRepository.Create(ticket);
            }
            session.Tickets = tickets;
            _unit.Save();
        }
Exemplo n.º 3
0
        public IEnumerable <SessionDTO> GetAllSessions()
        {
            IEnumerable <Session> sessions    = _unit.SessionRepository.GetAll();
            List <SessionDTO>     sessionsDTO = new List <SessionDTO>();

            foreach (Session s in sessions)
            {
                SessionDTO sess = _mapper.Map <SessionDTO>(s);
                sessionsDTO.Add(sess);
            }
            return(sessionsDTO);
        }
Exemplo n.º 4
0
        public SessionDTO GetSession(int id)
        {
            Session session = _unit.SessionRepository.Get(id);

            if (session == null)
            {
                throw new NotFoundException("Session is not found");
            }
            foreach (Ticket DataTicket in session.Tickets)
            {
                if (DataTicket.Status == "Booked" && DateTime.Now > DataTicket.ReservationTimeEnd)
                {
                    DataTicket.Status        = "Free";
                    DataTicket.UserProfileId = null;
                }
                _unit.TicketRepository.Update(DataTicket);
            }
            _unit.Save();
            SessionDTO sessionDTO = _mapper.Map <SessionDTO>(session);

            return(sessionDTO);
        }