private async Task <List <Tickets> > GetData(SqlDataReader reader)     //SQL helper
        {
            List <Tickets> lst = new List <Tickets>();

            try
            {
                List <Countries>      lstCtrys    = new List <Countries>();
                List <DepartureTimes> lstDepTimes = new List <DepartureTimes>();

                while (await reader.ReadAsync())
                {
                    Tickets t = new Tickets();
                    //execute this first else the other  code wont work
                    t.ID = (Guid)reader["ID"];
                    //only needs to run once per row in the reader
                    Countries ctry = await _countriesRepository.GetCountryByIdAsync((Guid)reader["CountryID"]);

                    //anything below this need to have t.ID not be a Guid.empty
                    List <string> lstCtryNames = new List <string>();
                    //we need these to make the for loops work
                    lstCtrys = await _countriesRepository.GetAllCountriesByTicketID(t.ID);

                    lstDepTimes = await _departureTRepository.GetDepartureTimesByTicketID(t.ID);

                    string Cname = "";

                    //needs the countries from
                    for (int i = 0; i < lstCtrys.Count(); i++)
                    {
                        Cname         = lstCtrys[i].CountryName;
                        t.Destination = Cname;

                        for (int ix = 0; ix < lstDepTimes.Count(); ix++)
                        {
                            Tickets tx = new Tickets();
                            tx.ID          = (Guid)reader["ID"];
                            tx.Available   = (int)reader["Available"];
                            tx.Price       = !Convert.IsDBNull(reader["Price"]) ? (int)reader["Price"] : 0;
                            tx.Country     = ctry.CountryName;
                            tx.Destination = Cname;
                            tx.Departure   = lstDepTimes[ix].Time;

                            lst.Add(tx);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
            }
            return(lst);
        }
Пример #2
0
 public async Task <List <Countries> > GetAllCountriesByTicketID(Guid TicketID)
 {
     return(await _countriesRepository.GetAllCountriesByTicketID(TicketID));
 }