public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null) //doesn't mean the airline in the parameter has the same values as the airline in the database with the same id
     {
         throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
     }
     _airlineDAO.Remove(airline);
 }
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null)
     {
         throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
     }
     _airlineDAO.Remove(airline);
 }
        /// <summary>
        /// gets an airline company by its ID
        /// </summary>
        /// <param name="id">the ID of the airline company you are looking for</param>
        /// <returns></returns>
        public AirlineCompany Get(long id)
        {
            log.Info($"entering Get with id = {id}");

            log.Debug($"creating sql connection with connection string: {connection_string}");
            using (SqlConnection con = new SqlConnection(connection_string))
            {
                try
                {
                    log.Debug("opening sql connection");
                    con.Open();
                    log.Debug("sql connection opened successfully");

                    log.Debug("creating SqlCommand with stored procedure: GET_AIRLINE_COMPANY");
                    using (SqlCommand cmd = new SqlCommand("GET_AIRLINE_COMPANY", con))
                    {
                        log.Debug($"adding parameter: id = {id}");
                        cmd.Parameters.AddWithValue("@id", id);
                        log.Debug("setting command type to 'StoredProcedure'");
                        cmd.CommandType = CommandType.StoredProcedure;

                        log.Debug("creating reader");
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            log.Debug("starting reading rows if there are any");
                            while (reader.Read())
                            {
                                log.Debug("new row found");

                                log.Debug("creating a new AirlineCompany POCO and putting sql parameters in it");
                                AirlineCompany airlineCompany = new AirlineCompany()
                                {
                                    ID          = (long)reader["ID"],
                                    AirlineName = (string)reader["AIRLINE_NAME"],
                                    UserName    = (string)reader["USER_NAME"],
                                    Password    = (string)reader["PASSWORD"],
                                    CountryCode = (long)reader["COUNTRY_CODE"]
                                };
                                log.Debug("airlineCompany created successfully");
                                log.Info($"exiting Get with return value: AirlineCompany: {airlineCompany}");
                                return(airlineCompany);
                            }
                            log.Info("exiting Get with return value: null");
                            return(null);
                        }
                    }
                }
                catch (SqlException ex)
                {
                    log.Fatal("FAILED TO OPEN SQL CONNECTION");
                    Console.WriteLine(ex.StackTrace);
                    return(null); //or should i crash it??
                }
            }
        }
Beispiel #4
0
        public AirlineCompany GetAirlineCompanyById(long id)
        {
            log.Info($"entering GetAirlineCompanyById with id = {id}");

            log.Debug("getting an AirlineCompany result from the airline DAO");
            AirlineCompany airline = _airlineDAO.Get(id);

            log.Debug("recieved airlineCompany result successfully");
            log.Info($"exiting GetAirlineCompanyById with return value: airlineCompany: {airline}");
            return(airline);
        }
Beispiel #5
0
 public void Update(AirlineCompany t)
 {
     using (SqlConnection con = new SqlConnection(AirlineProjectConfig.path))
     {
         con.Open();
         using (SqlCommand cmd = new SqlCommand($"update AirlineCompanies set ID = {t.ID}, AIRLINE_NAME = '{t.AirlineName}', USER_NAME = '{t.UserName}', PASSWORD = '******', COUNTRY_CODE = {t.CountryCode} where ID = {t.ID}", con))
         {
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
             }
         }
     }
 }
Beispiel #6
0
 public void Remove(AirlineCompany t)
 {
     using (SqlConnection con = new SqlConnection(AirlineProjectConfig.path))
     {
         con.Open();
         using (SqlCommand cmd = new SqlCommand($"DELETE FROM AirlineCompanies WHERE ID = {t.ID}", con))
         {
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
             }
         }
     }
 }
Beispiel #7
0
 public void Add(AirlineCompany t)
 {
     using (SqlConnection con = new SqlConnection(AirlineProjectConfig.path))
     {
         con.Open();
         using (SqlCommand cmd = new SqlCommand($"INSERT INTO AirlineCompanies VALUES ({t.ID}, '{t.AirlineName}', '{t.UserName}', '{t.Password}', {t.CountryCode})", con))
         {
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
             }
         }
     }
 }
 /// <summary>
 /// updates an airline company
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline">updates the airline company with this parameter's ID</param>
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null)
     {
         throw new UserNotFoundException($"failed to update airline! airline with username [{airline.UserName}] was not found!");
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to update airline! there is no country with id [{airline.CountryCode}]");
     }
     _airlineDAO.Update(airline);
 }
        /// <summary>
        /// removes an airline company
        /// </summary>
        /// <param name="token"></param>
        /// <param name="airline">removes an airline company that has this parameter's ID</param>
        public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
        {
            LoginHelper.CheckToken <Administrator>(token);
            POCOValidator.AirlineCompanyValidator(airline, true);
            if (_airlineDAO.Get(airline.ID) == null)
            {
                throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByAirlineCompanyId(airline);

            flights.ToList().ForEach(f => _ticketDAO.RemoveTicketsByFlight(f));
            flights.ToList().ForEach(f => _flightDAO.Remove(f)); //i think it's ok?
            _airlineDAO.Remove(airline);
        }
        public void CreateNewAirline(LoginToken <Administrator> token, AirlineCompany airline)
        {
            LoginHelper <Administrator> .CheckToken(token);

            if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
            {
                throw new AirlineNameAlreadyExistsException($"there is already an airline with the name '{airline.AirlineName}'");
            }
            if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null || _customerDAO.GetCustomerByUsername(airline.UserName) != null || airline.UserName == "admin")
            {
                throw new UsernameAlreadyExistsException($"Username '{airline.UserName}' is already taken!");
            }
            _airlineDAO.Add(airline);
        }
Beispiel #11
0
        /// <summary>
        /// removes an airline company
        /// </summary>
        /// <param name="token"></param>
        /// <param name="airline">removes an airline company that has this parameter's ID</param>
        public void RemoveAirline(LoginToken <Administrator> token, long airlineId)
        {
            LoginHelper.CheckToken <Administrator>(token);
            //POCOValidator.AirlineCompanyValidator(airline, true);
            AirlineCompany airlineToDelete = _airlineDAO.Get(airlineId);

            if (airlineToDelete == null)
            {
                throw new UserNotFoundException($"Failed to remove airline! Airline with ID [{airlineId}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByAirlineCompanyId(airlineToDelete);

            flights.ToList().ForEach(f => _ticketDAO.RemoveTicketsByFlight(f));
            flights.ToList().ForEach(f => _flightDAO.Remove(f));
            _airlineDAO.Remove(airlineToDelete);
        }
        /// <summary>
        /// removes an airline company
        /// </summary>
        /// <param name="t">removes the airline with the matching ID</param>
        public void Remove(AirlineCompany t)
        {
            using (SqlConnection con = new SqlConnection(AirlineProjectConfig.CONNECTION_STRING))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("REMOVE_AIRLINE_COMPANY", con))
                {
                    cmd.Parameters.AddWithValue("@id", t.ID);
                    cmd.CommandType = CommandType.StoredProcedure;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                    }
                }
            }
        }
        /// <summary>
        /// adds an airline company
        /// </summary>
        /// <param name="t">ID is generated on creation, leave it at 0</param>
        public void Add(AirlineCompany t)
        {
            using (SqlConnection con = new SqlConnection(AirlineProjectConfig.CONNECTION_STRING))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("ADD_AIRLINE_COMPANY", con))
                {
                    cmd.Parameters.AddWithValue("@airlineName", t.AirlineName);
                    cmd.Parameters.AddWithValue("@userName", t.UserName);
                    cmd.Parameters.AddWithValue("@password", t.Password);
                    cmd.Parameters.AddWithValue("@countryCode", t.CountryCode);
                    cmd.CommandType = CommandType.StoredProcedure;

                    t.ID = (long)(decimal)cmd.ExecuteScalar();
                }
            }
        }
 public void CreateNewAirline(AirlineCompany airline)
 {
     POCOValidator.AirlineCompanyValidator(airline, false);
     if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
     {
         throw new AirlineNameAlreadyExistsException($"failed to create airline! there is already an airline with the name '{airline.AirlineName}'");
     }
     if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null || _customerDAO.GetCustomerByUsername(airline.UserName) != null || airline.UserName == "admin")
     {
         throw new UsernameAlreadyExistsException($"failed to create airline! Username '{airline.UserName}' is already taken!");
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to create airline! there is no country with id [{airline.CountryCode}]");
     }
     _airlineDAO.Add(airline);
 }
        /// <summary>
        /// removes an airline company
        /// </summary>
        /// <param name="t">removes the airline with the matching ID</param>
        public void Remove(AirlineCompany t)
        {
            using (SqlConnection con = new SqlConnection(connection_string))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("REMOVE_AIRLINE_COMPANY", con))
                {
                    cmd.Parameters.AddWithValue("@id", t.ID);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.ExecuteNonQuery();
                    //using (SqlDataReader reader = cmd.ExecuteReader())
                    //{

                    //}
                }
            }
        }
Beispiel #16
0
        public bool TryAirlineLogin(string userName, string password, out LoginToken <AirlineCompany> token)
        {
            AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUsername(userName);

            if (airlineCompany != null)
            {
                if (airlineCompany.Password == password)
                {
                    token = new LoginToken <AirlineCompany>();
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException();
                }
            }
            token = null;
            return(false);
        }
        public bool TryAirlineLogin(string userName, string password, out LoginToken <AirlineCompany> token)
        {
            AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUsername(userName);

            if (airlineCompany != null)
            {
                if (airlineCompany.Password == password)
                {
                    token = new LoginToken <AirlineCompany>(airlineCompany);
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException($"failed to login as [{userName}], you entered a wrong password! [{password}]");
                }
            }
            token = null;
            return(false);
        }
Beispiel #18
0
 /// <summary>
 /// can change all the airline's details except ID and Password
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline"></param>
 public void ModifyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (airline.ID != token.User.ID)
     {
         throw new InaccessibleAirlineCompanyException($"failed to modify details! this is not your account!"); //will it ever happen? who knows...
     }
     if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
     {
         throw new AirlineNameAlreadyExistsException($"failed to modify details! there is already and airline with the name [{airline.AirlineName}]");
     }
     if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null)
     {
         throw new UsernameAlreadyExistsException($"failed to modify details! username [{airline.UserName}] is already taken!");
     }
     airline.Password = _airlineDAO.Get(airline.ID).Password; // i guess..
     _airlineDAO.Update(airline);
 }
        /// <summary>
        /// updates an airline company
        /// </summary>
        /// <param name="t">updates the airline with the matching id, updates all fields</param>
        public void Update(AirlineCompany t)
        {
            using (SqlConnection con = new SqlConnection(AirlineProjectConfig.CONNECTION_STRING))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("UPDATE_AIRLINE_COMPANY", con))
                {
                    cmd.Parameters.AddWithValue("@airlineName", t.AirlineName);
                    cmd.Parameters.AddWithValue("@userName", t.UserName);
                    cmd.Parameters.AddWithValue("@password", t.Password);
                    cmd.Parameters.AddWithValue("@countryCode", t.CountryCode);
                    cmd.Parameters.AddWithValue("@id", t.ID);
                    cmd.CommandType = CommandType.StoredProcedure;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                    }
                }
            }
        }
        /// <summary>
        /// updates an airline company
        /// </summary>
        /// <param name="t">updates the airline with the matching id, updates all fields</param>
        public void Update(AirlineCompany t)
        {
            using (SqlConnection con = new SqlConnection(connection_string))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("UPDATE_AIRLINE_COMPANY", con))
                {
                    cmd.Parameters.AddWithValue("@airlineName", t.AirlineName);
                    cmd.Parameters.AddWithValue("@userName", t.UserName);
                    cmd.Parameters.AddWithValue("@password", t.Password);
                    cmd.Parameters.AddWithValue("@countryCode", t.CountryCode);
                    cmd.Parameters.AddWithValue("@id", t.ID);
                    cmd.CommandType = CommandType.StoredProcedure;


                    cmd.ExecuteNonQuery();
                    //using (SqlDataReader reader = cmd.ExecuteReader())
                    //{

                    //}
                }
            }
        }
        ///////////////////////////AirlineCompanies//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void AddAirlineCompany(AirlineCompany airlineCompany)
        {
            _airlineDAO.Add(airlineCompany);
        }
        public AirlineCompany GetAirlineCompany(int id)
        {
            AirlineCompany airlineCompany = _airlineDAO.Get(id);

            return(airlineCompany);
        }
Beispiel #23
0
 public void Update(AirlineCompany t)
 {
     throw new NotImplementedException();
 }
        public AirlineCompany GetAirlineCompanyById(long id)
        {
            AirlineCompany airline = _airlineDAO.Get(id);

            return(airline);
        }
        public override bool Equals(object obj)
        {
            AirlineCompany other = (AirlineCompany)obj;

            return(this == other);
        }
 /// <summary>
 /// can change all the airline's details except ID and Password
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline"></param>
 public void ModifyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline)
 {
     //leave password and id alone
     throw new NotImplementedException();
 }
 public void ModifyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline)
 {
     throw new NotImplementedException();
 }
        public AirlineCompany GetAirlineByUsername(string name)
        {
            AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUsername(name);

            return(airlineCompany);
        }
 public void RemoveAirlineCompany(AirlineCompany t)
 {
     _airlineDAO.Remove(t);
 }
 public void UpdateAirlineCompany(AirlineCompany t)
 {
     _airlineDAO.Update(t);
 }