//Update Details Of Current Customer (Without Password). public void Update(Customer t) { using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING)) { using (SqlCommand cmd1 = new SqlCommand($"Select User_Name from Customers where Id = {t.Id}", conn)) { SqlDataReader reader = cmd1.ExecuteReader(); if (reader.Read() == true) { UserNames.RemoveUserName((string)reader["User_Name"]); } } using (SqlCommand cmd2 = new SqlCommand($"Update Customers Set First_Name = '{t.First_Name}', Last_Name = '{t.Last_Name}', User_Name = '{t.User_Name}'," + $"Address = '{t.Address}', Credit_Card_Number = '{t.Credit_Card_Number}' Where Id = {t.Id}", conn)) { SqlDataReader reader = cmd2.ExecuteReader(); if (reader.Read() == true) { cmd2.ExecuteNonQuery(); UserNames.AddUserName(t.User_Name); return; } } } throw new UserNotExistException($"Sorry, But We Don't Found {t.User_Name}."); }
// Update Airline Company (Except Password). public void Update(AirlineCompany t) { using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING)) { using (SqlCommand cmd1 = new SqlCommand($"Select User_Name from AirlineCompanies where Id = {t.Id}", conn)) { SqlDataReader reader = cmd1.ExecuteReader(); if (reader.Read() == true) { UserNames.RemoveUserName((string)reader["User_Name"]); } } using (SqlCommand cmd2 = new SqlCommand($"Update AirLineCompanies Set Airline_Name = '{t.Airline_Name}', User_Name = '{t.User_Name}'," + $"Country_Code = '{t.Country_Code}' Where Id = {t.Id}", conn)) { SqlDataReader reader = cmd2.ExecuteReader(); if (reader.Read() == true) { cmd2.ExecuteNonQuery(); UserNames.AddUserName(t.User_Name); return; } } } throw new UserNotExistException($"Sorry, But We Don't Found {t.User_Name}."); }
//Remove Customer. public void Remove(Customer t) { using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING)) { using (SqlCommand cmd = new SqlCommand($"Delete From Customers where UserName = {t.User_Name}", conn)) { SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read() == true) { cmd.ExecuteNonQuery(); UserNames.RemoveUserName(t.User_Name); return; } } } throw new UserNotExistException($"Sorry, But We Don't Found {t.User_Name}."); }
//Remove Customer. public void Remove(Customer t) { using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING)) { conn.Open(); using (SqlCommand cmd = new SqlCommand($"Delete from Tickets Where Customer_Id = (select Top 1 Id from Customers where User_Name like '{t.User_Name}');" + $"Delete From Customers where User_Name like '{t.User_Name}'", conn)) { SqlDataReader reader = cmd.ExecuteReader(); if (reader.RecordsAffected > 0) { UserNames.RemoveUserName(t.User_Name); return; } } } throw new UserNotExistException($"Sorry, But We Don't Found {t.User_Name}."); }
// Remove Airline Company. public void Remove(AirlineCompany t) { using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING)) { conn.Open(); using (SqlCommand cmd = new SqlCommand($"Delete from Tickets Where Flight_Id = (select TOP 1 Id from Flights where AirlineCompany_Id like (select Id from AirlineCompanies where User_Name like '{t.User_Name}')); " + $"Delete from Flights Where AirlineCompany_Id = (select Id from AirlineCompanies where User_Name like '{t.User_Name}');" + $"Delete from AirlineCompanies Where User_Name like '{t.User_Name}'", conn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.RecordsAffected > 0) { UserNames.RemoveUserName(t.User_Name); return; } } } } throw new UserNotExistException($"Sorry, But We Don't Found {t.User_Name}."); }