Example #1
0
        private async Task <List <DepartureTimes> > GetData(SqlDataReader reader)
        {
            List <DepartureTimes> lst = new List <DepartureTimes>();

            try
            {
                while (await reader.ReadAsync())
                {
                    DepartureTimes dt = new DepartureTimes()
                    {
                        ID   = (Guid)reader["ID"],
                        Time = Convert.ToDateTime(reader["DepartureTime"])
                    };


                    lst.Add(dt);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
            }
            return(lst);
        }
        private async Task <Tickets> GetMyTicketData(SqlDataReader reader, Guid CtryID, Guid DepTID)
        {
            Tickets        t         = new Tickets();
            DepartureTimes depTimesX = new DepartureTimes();
            Countries      ctryX     = new Countries();

            try
            {
                while (await reader.ReadAsync())
                {
                    ctryX = await _countriesRepository.GetCountryByIdAsync(CtryID);

                    depTimesX = await _departureTRepository.GetDepartureTimeByID(DepTID);

                    t.ID        = (Guid)reader["ID"];
                    t.Available = (int)reader["Available"];
                    t.Price     = !Convert.IsDBNull(reader["Price"]) ? (int)reader["Price"] : 0;
                    Countries ctry = await _countriesRepository.GetCountryByIdAsync((Guid)reader["CountryID"]);

                    t.Country     = ctry.CountryName;
                    t.Departure   = depTimesX.Time;
                    t.Destination = ctryX.CountryName;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
            }
            return(t);
        }
        public async Task <DepartureTimes> GetDepartureTByID(Guid id)
        {
            DepartureTimes depTime = new DepartureTimes();

            depTime = await _dataService.GetDepartureTimeByID(id);

            return(depTime);
        }
        public async Task <DepartureTimes> GetDepartureTByTime([FromQuery] string time)
        {
            DepartureTimes depTime = new DepartureTimes();
            DateTime       dTime   = DateTime.Parse(time);

            depTime = await _dataService.GetDepartureTimesByTime(dTime);

            return(depTime);
        }
        //"buy" a ticket and then return the same list of tickets using the user defined parameters. needs the parameters of the "bought" ticket and the parameters of the original search parameters defined by an 'o' in front.
        public async Task <IActionResult> Buy(string ticketID, string origin, string destination, string departure, string returnDate, string wayString, string oDeparture, string oReturnDate, string oOrigin, string oDestination)
        {
            User usr = await GetUser();

            string url = "https://localhost:44355/EasyFlights/Tickets/SpecificTicket?origin=" + oOrigin + "&destination=" + oDestination + "&leaveDate=" + oDeparture + "&returnDate=" + oReturnDate + "&passengers=" + 1 + "&oneWay=" + wayString;

            Countries c = await GetCountries(destination);

            DepartureTimes dp = await GetDepartures(departure);

            List <Tickets> lstT = await GetTickets(url);


            //gets the tickets that were searched for back so that one can order a second ticket with the same parameters.
            List <TicketModel> lst = new List <TicketModel>();

            _logger.LogInformation("{Code}: Changing list of tickets to conform to view needs", LoggingEvents.ListItems);
            lst = await GetReturnTickets(lstT, returnDate);

            if (lst == null)
            {
                _logger.LogWarning("{Code}: error when changing list to conform to view needs", LoggingEvents.ListItems);
            }

            // "buys" the ticket
            string      urlR     = "https://localhost:44355/EasyFlights/users/reserve?userID=" + usr.ID + "&ticketID=" + ticketID + "&destinationID=" + c.ID + "&departureID=" + dp.ID;
            HttpContent Content  = new StringContent("");
            var         response = await Client.PostAsync(urlR, Content);

            var result = await response.Content.ReadAsAsync <List <TicketModel> >();

            response.EnsureSuccessStatusCode();
            lst[0].Bought = 1;
            string          name = HttpContext.User.Identity.Name;
            ApplicationUser user = await _userManager.FindByEmailAsync(name);

            int totPoints = await GetBonusPoints(name);

            if (totPoints >= 15)
            {
                await AssignSuperUser(user);
            }
            else if (totPoints < 15)
            {
                await CheckCurrentRole(user);
            }

            return(View("index", lst));
        }
Example #6
0
        public async Task <DepartureTimes> GetDepartureTimesByTime(DateTime time)
        {
            DepartureTimes depTime = new DepartureTimes();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     sql = "SELECT * FROM DepartureTimes Where DepartureTime = @Time";
                SqlCommand cmd = new SqlCommand(sql, con)
                {
                    CommandType = System.Data.CommandType.Text,
                };
                cmd.Parameters.AddWithValue("@Time", time);

                con.Open();
                SqlDataReader reader = await cmd.ExecuteReaderAsync();

                depTime = (await GetData(reader))[0];
                con.Close();
            }
            return(depTime);
        }
        public async Task <List <Tickets> > GetTicketsByCtry_Time(string origin, string destination, DateTime departureTime)
        {
            List <Tickets> lst = new List <Tickets>();

            Countries originCtry = await _countriesRepository.GetCountryByName(origin);

            Countries destinationCtry = await _countriesRepository.GetCountryByName(destination);

            bool                  noTime         = false;
            DepartureTimes        departureTimes = new DepartureTimes();
            List <Guid>           lstdepTID      = new List <Guid>();
            List <DepartureTimes> lstDepTimes    = new List <DepartureTimes>();


            if (departureTime.Hour == 00)
            {
                noTime = true;
            }
            else
            {
                noTime = false;
            }


            if (noTime == true)
            {
                for (int i = 4; i <= 22;)
                {
                    DateTime times = departureTime.AddHours(i);

                    lstDepTimes.Add(await _departureTRepository.GetDepartureTimesByTime(times));
                    i += 2;
                }

                int ix = 0;

                foreach (var item in lstDepTimes)
                {
                    departureTimes = await _departureTRepository.GetDepartureTimesByTime(lstDepTimes[ix].Time);

                    ix += 1;
                    lstdepTID.Add(departureTimes.ID);

                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        string     sql = "Select * From Tickets Where CountryID = @Origin";
                        SqlCommand cmd = new SqlCommand(sql, con)
                        {
                            CommandType = System.Data.CommandType.Text,
                        };
                        cmd.Parameters.AddWithValue("@Origin", originCtry.ID);

                        con.Open();
                        SqlDataReader reader = await cmd.ExecuteReaderAsync();

                        lst = await GetDataByDestDepT(reader, destinationCtry.ID, lstdepTID);

                        con.Close();
                    }
                }
                return(lst);
            }
            else
            {
                DepartureTimes depTime = await _departureTRepository.GetDepartureTimesByTime(departureTime);

                List <Guid> lstdepTime = new List <Guid>
                {
                    depTime.ID
                };

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    string     sql = "Select * From Tickets Where CountryID = @Origin";
                    SqlCommand cmd = new SqlCommand(sql, con)
                    {
                        CommandType = System.Data.CommandType.Text,
                    };
                    cmd.Parameters.AddWithValue("@Origin", originCtry.ID);

                    con.Open();
                    SqlDataReader reader = await cmd.ExecuteReaderAsync();

                    lst = await GetDataByDestDepT(reader, destinationCtry.ID, lstdepTime);

                    con.Close();
                }
                return(lst);
            }
        }