Esempio n. 1
0
 // 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}.");
 }
Esempio n. 2
0
 //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}.");
 }
        // Add New Admin.
        public long Add(Administrator t)
        {
            long newId;

            using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
            {
                conn.Open();
                using (SqlCommand cmd1 = new SqlCommand($"Select * from UserNames where User_Names = '{t.User_Name.ToUpper()}'", conn))
                {
                    SqlDataReader reader = cmd1.ExecuteReader();
                    if (reader.Read() == true || t.User_Name.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
                    {
                        throw new UserNameIsAlreadyExistException($"Sorry But '{t.User_Name}' Is Already Exist");
                    }
                    conn.Close();
                }
                using (SqlCommand cmd2 = new SqlCommand($"Insert Into Administrators(User_Name,Password) Values('{t.User_Name}','{t.Password}'); SELECT CAST(scope_identity() AS bigint)", conn))
                {
                    conn.Open();
                    cmd2.Parameters.AddWithValue($"{t.User_Name}", "bar");
                    newId = (long)cmd2.ExecuteScalar();
                    UserNames.AddUserName(t.User_Name);
                }
            }
            return(newId);
        }
Esempio n. 4
0
 //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}.");
 }
Esempio n. 5
0
 //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}.");
 }
Esempio n. 6
0
 // Add New Customer.
 public void Add(Customer t)
 {
     using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
     {
         using (SqlCommand cmd1 = new SqlCommand($"Select * from UserNames where User_Names = {t.User_Name.ToUpper()}", conn))
         {
             SqlDataReader reader = cmd1.ExecuteReader();
             if (reader.Read() == true || t.User_Name.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
             {
                 throw new UserNameIsAlreadyExistException($"Sorry But '{t.User_Name}' Is Already Exist");
             }
         }
         using (SqlCommand cmd2 = new SqlCommand($"Insert Into Customers(First_Name, Last_Name, User_Name, Password, Address, Credit_Card_Number) Values" +
                                                 $"('{t.First_Name}','{t.Last_Name}','{t.User_Name}','{t.Password}','{t.Address}','{t.Credit_Card_Number}')", conn))
         {
             cmd2.ExecuteNonQuery();
             UserNames.AddUserName(t.User_Name);
         }
     }
 }
Esempio n. 7
0
 // Add New Airline Company.
 public void Add(AirlineCompany t)
 {
     using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
     {
         using (SqlCommand cmd1 = new SqlCommand($"Select * from UserNames where User_Names = {t.User_Name.ToUpper()}", conn))
         {
             SqlDataReader reader = cmd1.ExecuteReader();
             if (reader.Read() == true || t.User_Name.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
             {
                 throw new UserNameIsAlreadyExistException($"Sorry But '{t.User_Name}' Is Already Exist");
             }
         }
         using (SqlCommand cmd2 = new SqlCommand($"Insert Into AirlineCompanies(Airline_Name,User_Name,Password,Country_Code) Values" +
                                                 $"('{t.Airline_Name}','{t.User_Name}','{t.Password}','{t.Country_Code}')", conn))
         {
             cmd2.ExecuteNonQuery();
             UserNames.AddUserName(t.User_Name);
         }
     }
 }
Esempio n. 8
0
 // 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}.");
 }
 // Add New Admin.
 public void Add(Administrator t)
 {
     using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
     {
         conn.Open();
         using (SqlCommand cmd1 = new SqlCommand($"Select * from UserNames where User_Names = '{t.User_Name.ToUpper()}'", conn))
         {
             SqlDataReader reader = cmd1.ExecuteReader();
             if (reader.Read() == true || t.User_Name.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
             {
                 throw new UserNameIsAlreadyExistException($"Sorry But '{t.User_Name}' Is Already Exist");
             }
             conn.Close();
         }
         using (SqlCommand cmd2 = new SqlCommand($"Insert Into Administrators(User_Name,Password) Values('{t.User_Name}','{t.Password}')", conn))
         {
             conn.Open();
             cmd2.ExecuteNonQuery();
             UserNames.AddUserName(t.User_Name);
         }
     }
 }