Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sometime">Time that defines time range of the flights the method returns</param>
        /// <param name="viewStatus">Defines if flights are for Departures or Arrivals</param>
        /// <param name="viewTime">Defines if Departures or Arrival was or will be</param>
        /// <returns></returns>
        public List <T> GetAllFlightsThatTakeOffInSomeTimeFromNow(TimeSpan sometime, RazorViewStatus viewStatus, RazorViewStatus viewTime)
        {
            try
            {
                List <T> toReturn = new List <T>();
                _connection.Open();
                _command.CommandType = CommandType.Text;
                var      dt = DateTime.Now;
                DateTime selectionDateTime = DateTime.Now.Add(sometime);

                //imminentFlightActionTime -> depatrure time or landing time of the flight in question, depending on "viewStatus" parameter of the method
                string imminentFlightActionTime = "DEPARTURE_TIME";
                char   comparsionSymbol         = '<';
                char   comparsionSymbol2        = '>';


                if (viewStatus == RazorViewStatus.Landings)
                {
                    imminentFlightActionTime = "LANDING_TIME";
                    if (viewTime == RazorViewStatus.Past)
                    {
                        comparsionSymbol  = '<';
                        comparsionSymbol2 = '>';
                        selectionDateTime = DateTime.Now.Subtract(sometime);
                    }
                }

                _command.CommandText = $"select * from {GetTableName(typeof(T))} WHERE {imminentFlightActionTime} {comparsionSymbol}= '{selectionDateTime}' AND {imminentFlightActionTime} {comparsionSymbol2}= '{DateTime.Now}'";
                using (SqlDataReader reader = _command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        T poco = new T();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            object value = reader[i];
                            if (reader[i] is DBNull && typeof(T).GetProperties()[i].GetType().Name.ToLower().Equals("string"))
                            {
                                typeof(T).GetProperties()[i].SetValue(poco, string.Empty);
                            }
                            if (reader[i] is DBNull && typeof(T).GetProperties()[i].GetType().Name.ToLower().Contains("int"))
                            {
                                typeof(T).GetProperties()[i].SetValue(poco, 0);
                            }

                            if (!(reader[i] is DBNull))
                            {
                                typeof(T).GetProperties()[i].SetValue(poco, value);
                            }
                        }
                        toReturn.Add(poco);
                    }
                }
                return(toReturn);
            }
            finally { _connection.Close(); }
        }
Example #2
0
        public List <Flight> GetAllFlightsThatTakeOffInSomeTimeFromNow(TimeSpan someTime, RazorViewStatus status)
        {
            if (status == RazorViewStatus.Landings)
            {
                List <Flight> oveallLandingFlights;
                List <Flight> willLandFlights;

                //first of all, flights that already landed
                oveallLandingFlights = _flightDAO.GetAllFlightsThatTakeOffInSomeTimeFromNow(someTime, status, RazorViewStatus.Future);
                //second of all, flights tht will land in 4 hours
                willLandFlights = _flightDAO.GetAllFlightsThatTakeOffInSomeTimeFromNow(new TimeSpan(4, 0, 0), status, RazorViewStatus.Past);

                oveallLandingFlights.AddRange(willLandFlights);

                return(oveallLandingFlights);
            }

            return(_flightDAO.GetAllFlightsThatTakeOffInSomeTimeFromNow(someTime, status, RazorViewStatus.Future));
        }