/// <summary> /// Changes the details of the airline company. /// </summary> /// <param name="token"></param> /// <param name="airline"></param> public void MofidyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline) { if (token.User.Id == airline.Id) { _airlineDAO.Update(airline); } else { throw new DoesNotBelongToThisAirlineCompanyException($"You can not change airline company: {airline.Id} because its not belong to you"); } }
public override bool Equals(object ob) { if (ReferenceEquals(ob, null)) { return(false); } AirlineCompany c = ob as AirlineCompany; if (ReferenceEquals(c, null)) { return(false); } return(this.Id == c.Id); }
/// <summary> /// Changes the password of the airline company. /// </summary> /// <param name="token"></param> /// <param name="oldPassword"></param> /// <param name="newPassword"></param> public void ChangeMyPassword(LoginToken <AirlineCompany> token, string oldPassword, string newPassword) { AirlineCompany airlineCompany = _airlineDAO.GetAirlineByPassword(oldPassword); if (airlineCompany != null) { airlineCompany.Password = newPassword; _airlineDAO.Update(airlineCompany); } else { throw new WrongPasswordException("The old password is incorrect"); } }
/// <summary> /// Changes the details of the airline company. /// </summary> /// <param name="company"></param> public void Update(AirlineCompany company) { using (SqlConnection conn = new SqlConnection(FlightCenterConfig.dbName)) { SqlCommand cmd = new SqlCommand($"UPDATE AirlineCompany SET AirlineName='{company.AirlineName}'," + $" UserName='******',Password='******',CountryCode={company.CountryCode}" + $"WHERE Id={company.Id}", conn); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } }
/// <summary> /// Adds a airline company to the data base. /// </summary> /// <param name="company"></param> public AirlineCompany Add(AirlineCompany company) { using (SqlConnection conn = new SqlConnection(FlightCenterConfig.dbName)) { SqlCommand cmd = new SqlCommand($"INSERT INTO AirlineCompany (AirlineName,UserName,Password,CountryCode)" + $"VALUES('{company.AirlineName}','{company.UserName}','{company.Password}',{company.CountryCode})", conn); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Connection.Close(); return(company); } }
public bool CheckUserNameAndPwdAirline(LoginToken <Administrator> token, string username, string password) { AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUserName(username); if (airlineCompany != null) { if (airlineCompany.Password == password) { return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Gives a airline company by user name. /// </summary> /// <param name="name"></param> /// <returns></returns> public AirlineCompany GetAirlineByUserName(string name) { using (SqlConnection conn = new SqlConnection(FlightCenterConfig.dbName)) { SqlCommand cmd = new SqlCommand($"SELECT * FROM AirlineCompany WHERE UserName='******'", conn); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); if (reader.Read() == true) { AirlineCompany company = new AirlineCompany { Id = (long)reader["Id"], AirlineName = (string)reader["AirlineName"], UserName = (string)reader["UserName"], Password = (string)reader["Password"], CountryCode = (long)reader["CountryCode"] }; cmd.Connection.Close(); return(company); } else { Debug.Write("there is no airline company with this name"); return(null); } } }
/// <summary> /// Changes the details of the airline company. /// </summary> /// <param name="token"></param> /// <param name="airline"></param> public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline) { _airlineDAO.Update(airline); }
/// <summary> /// Removes a ailine company from the data base. /// </summary> /// <param name="token"></param> /// <param name="airline"></param> public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline) { _airlineDAO.Remove(airline); }
/// <summary> /// Adds a airline company to the data base. /// </summary> /// <param name="token"></param> /// <param name="airline"></param> public AirlineCompany CreateNewAirline(LoginToken <Administrator> token, AirlineCompany airline) { AirlineCompany airlineCompany = _airlineDAO.Add(airline); return(airlineCompany); }
/// <summary> /// Remove the airline company from the database. /// </summary> /// <param name="company"></param> public void Remove(AirlineCompany company) { IList <Flight> flights = new List <Flight>(); using (SqlConnection conn = new SqlConnection(FlightCenterConfig.dbName)) { SqlCommand cmd1 = new SqlCommand($"SELECT * FROM Flights WHERE AirLineCompanyId ={company.Id}", conn); cmd1.Connection.Open(); cmd1.CommandType = CommandType.Text; SqlDataReader reader = cmd1.ExecuteReader(CommandBehavior.Default); while (reader.Read() == true) { Flight flight = new Flight { Id = (long)reader["Id"], AirlineCompanyId = (long)reader["AirLineCompanyId"], OriginCountryCode = (long)reader["OriginCountryCode"], DestinationCountryCode = (long)reader["DestinationCountryCode"], DepartureTime = (DateTime)reader["DepartureTime"], LandingTime = (DateTime)reader["LandingTime"], RemainingTickets = (int)reader["RemainingTickets"], }; flights.Add(flight); } cmd1.Connection.Close(); foreach (Flight flight in flights) { long id = flight.Id; SqlCommand cmd2 = new SqlCommand("DELETE_FROM_TICKETS", conn); cmd2.Parameters.Add(new SqlParameter("@flightId", id)); cmd2.Connection.Open(); cmd2.CommandType = CommandType.StoredProcedure; cmd2.ExecuteNonQuery(); cmd2.Connection.Close(); } SqlCommand cmd3 = new SqlCommand($"DELETE FROM Flights WHERE AirLineCompanyId ={company.Id}", conn); cmd3.Connection.Open(); cmd3.CommandType = CommandType.Text; cmd3.ExecuteNonQuery(); cmd3.Connection.Close(); SqlCommand cmd = new SqlCommand($"DELETE FROM AirlineCompany WHERE Id ={company.Id}", conn); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } }