public async Task <IActionResult> Edit(int id, [Bind("Key,KeySeller,KeyBuyer,KeyTicket,DateOfTrade")] TicketsHistory ticketsHistory)
        {
            if (id != ticketsHistory.Key)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ticketsHistory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TicketsHistoryExists(ticketsHistory.Key))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KeyBuyer"]  = new SelectList(_context.Users, "Key", "City", ticketsHistory.KeyBuyer);
            ViewData["KeySeller"] = new SelectList(_context.Users, "Key", "City", ticketsHistory.KeySeller);
            ViewData["KeyTicket"] = new SelectList(_context.PlainTickets, "Key", "FlightNumber", ticketsHistory.KeyTicket);
            return(View(ticketsHistory));
        }
        public async Task <IActionResult> Create([Bind("Key,KeySeller,KeyBuyer,KeyTicket,DateOfTrade")] TicketsHistory ticketsHistory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ticketsHistory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KeyBuyer"]  = new SelectList(_context.Users, "Key", "City", ticketsHistory.KeyBuyer);
            ViewData["KeySeller"] = new SelectList(_context.Users, "Key", "City", ticketsHistory.KeySeller);
            ViewData["KeyTicket"] = new SelectList(_context.PlainTickets, "Key", "FlightNumber", ticketsHistory.KeyTicket);
            return(View(ticketsHistory));
        }
        public async Task <IActionResult> BuyFlight([Bind("Key,OwnerId")] PlainTickets plainTickets)
        {
            if (ModelState.IsValid)
            {
                // Add to history
                // TODO: replace t with current user
                TicketsHistory ticketsHistory = new TicketsHistory(5, plainTickets.OwnerId, plainTickets.Key);
                _context.Add(ticketsHistory);

                // Remove from plain tickets
                var a = _context.PlainTickets.First(x => x.Key == plainTickets.Key);
                a.IsSold = true;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }


            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
 public ServerSideSession(int id, byte[] secret, string remoteLogin, bool legacy)
     : base(id, secret, remoteLogin, legacy)
 {
     Ticket = new TicketsHistory();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Singleton - private constructor,
        /// acsess the clas by it's name and the method GetInstance instead.
        /// </summary>
        private FlyingCenterSystem()
        {
            try
            {
                _threadTimeDelatyMilliseconds = int.Parse(ConfigurationManager.AppSettings["ThreadDelayTime"]);
            }
            catch (ArgumentNullException)
            {
                _threadTimeDelatyMilliseconds = 86400000;
            }

            _wakeUpAndSing = new Thread(() =>
            {
                Thread.Sleep(_threadTimeDelatyMilliseconds);
                var _currentFlightDAO          = this.CreateApproptiateDAOInstance <Flight>();
                var _currentFlightHistoryDAO   = this.CreateApproptiateDAOInstance <FlightsHistory>();
                var _currentTicketsDAO         = this.CreateApproptiateDAOInstance <Ticket>();
                var _currentTicketHistoryDAO   = this.CreateApproptiateDAOInstance <TicketsHistory>();
                var _currentHistoryTrackingDAO = this.CreateApproptiateDAOInstance <HistoryTracking>();

                foreach (var s_Flight in _currentFlightDAO.GetAll())
                {
                    if (s_Flight.LANDING_TIME.Hour - DateTime.Now.Hour > 3)
                    {
                        FlightsHistory historyItemFlight = new FlightsHistory();
                        for (int i = 0; i < s_Flight.GetType().GetProperties().Length; i++)
                        {
                            historyItemFlight.GetType().GetProperties()[i].SetValue(historyItemFlight, s_Flight.GetType().GetProperties()[i].GetValue(s_Flight));
                        }
                        _currentFlightHistoryDAO.Add(historyItemFlight);

                        HistoryTracking thisFlightTrackingInfo    = new HistoryTracking();
                        thisFlightTrackingInfo.HISTORY_ENTRY_ID   = s_Flight.ID;
                        thisFlightTrackingInfo.HISTORY_ENTRY_KIND = s_Flight.GetType().Name;
                        thisFlightTrackingInfo.HISTORY_ENTRY_TIME = DateTime.UtcNow;

                        _currentHistoryTrackingDAO.Add(thisFlightTrackingInfo);

                        _currentFlightDAO.Remove(s_Flight);

                        Ticket ticketFromFlight          = _currentTicketsDAO.GetSomethingBySomethingInternal(s_Flight.ID, (int)TicketPropertyNumber.FLIGHT_ID);
                        TicketsHistory historyItemTicket = new TicketsHistory();
                        for (int i = 0; i < ticketFromFlight.GetType().GetProperties().Length; i++)
                        {
                            historyItemTicket.GetType().GetProperties()[i].SetValue(historyItemTicket, ticketFromFlight.GetType().GetProperties()[i].GetValue(ticketFromFlight));
                        }
                        _currentTicketHistoryDAO.Add(historyItemTicket);

                        HistoryTracking thisTicketTrackingInfo    = new HistoryTracking();
                        thisTicketTrackingInfo.HISTORY_ENTRY_ID   = ticketFromFlight.ID;
                        thisTicketTrackingInfo.HISTORY_ENTRY_KIND = ticketFromFlight.GetType().Name;
                        thisTicketTrackingInfo.HISTORY_ENTRY_TIME = DateTime.UtcNow;

                        _currentHistoryTrackingDAO.Add(thisTicketTrackingInfo);

                        _currentTicketsDAO.Remove(ticketFromFlight);
                    }
                }
            });
            _wakeUpAndSing.Start();
        }