// Search Airline Company By Id.
        public AirlineCompany GetAirlineById(LoginToken <Administrator> token, int id)
        {
            AirlineCompany airline = new AirlineCompany();

            if (UserIsValid(token))
            {
                airline = _airlineDAO.GetById(id);
            }
            return(airline);
        }
コード例 #2
0
 // Change Password Of Current Airline.
 public void ChangePassword(AirlineCompany airline)
 {
     using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
     {
         conn.Open();
         using (SqlCommand cmd = new SqlCommand($"Update AirLineCompanies Set Password = '******' Where Id = {airline.Id}", conn))
         {
             cmd.ExecuteNonQuery();
         }
     }
 }
        // Search Airline By UserName.
        public AirlineCompany GetAirlineByUserName(LoginToken <Administrator> token, string userName)
        {
            AirlineCompany airline = new AirlineCompany();

            if (UserIsValid(token))
            {
                User airlineUser = _userDAO.GetUserByUserName(userName);
                if (airlineUser != null)
                {
                    airline = _airlineDAO.GetById(airlineUser.Id);
                }
            }
            return(airline);
        }
コード例 #4
0
 // Remove Airline Company.
 public bool 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 = (select Id from AirlineCompanies where Id = {t.Id})); " +
                                                $"Delete from Flights Where AirlineCompany_Id = (select Id from AirlineCompanies where Id = {t.Id});" +
                                                $"Delete from AirlineCompanies where Id = {t.Id}", conn))
         {
             cmd.ExecuteNonQuery();
             return(true);
         }
     }
     throw new UserNotExistException("Sorry, But This Company Does Not Exist.");
 }
コード例 #5
0
 // Update Airline Company (Except Password).
 public bool Update(AirlineCompany t)
 {
     using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
     {
         conn.Open();
         using (SqlCommand cmd = new SqlCommand($"Update AirLineCompanies Set Airline_Name = '{t.Airline_Name}'," +
                                                $"Country_Code = '{t.Country_Code}' Where Id = {t.Id}", conn))
         {
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.RecordsAffected > 0)
                 {
                     return(true);
                 }
             }
         }
     }
     throw new UserNotExistException("Sorry, But This Airline Does Not Exist.");
 }
コード例 #6
0
        //====== Crud Commands ======//

        // Add New Airline Company.
        public long Add(AirlineCompany t)
        {
            long airlineNumber = 0;

            using (SqlConnection conn = new SqlConnection(FlyingCenterConfig.CONNECTION_STRING))
            {
                using (SqlCommand cmd = new SqlCommand($"Add_Airline", conn))
                {
                    cmd.Connection.Open();

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", t.Id);
                    cmd.Parameters.AddWithValue("@Airline_Name", t.Airline_Name);
                    cmd.Parameters.AddWithValue("@Country_Code", t.Country_Code);

                    airlineNumber = (long)cmd.ExecuteScalar();
                }
            }
            return(airlineNumber);
        }
 // Force Change Password For Some Airline.
 public void ForceChangePasswordForAirline(LoginToken <Administrator> token, AirlineCompany airline, string newPassword)
 {
     if (UserIsValid(token) && airline != null)
     {
         User airlineUser = _userDAO.GetUserById(airline.Id);
         if (airlineUser != null)
         {
             _userDAO.ForceChangePasswordForUser(airlineUser, newPassword);
             airline.ChangePassword(newPassword);
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Admin: {token.User.User_Name} Tried To Change Password In Force For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", true);
         }
         else
         {
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Admin: {token.User.User_Name} Tried To Change Password In Force For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", false);
             throw new UserNotExistException($"Sorry, But '{airline.User_Name}' Is Not Exist.");
         }
     }
     else
     {
         _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Anonymous User Tried To Change Password In Force For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", false);
     }
 }
 // Update Details For Some Airline Company.
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline)
 {
     if (UserIsValid(token) && airline != null)
     {
         User airlineUser = _userDAO.GetUserById(airline.Id);
         if (airlineUser != null)
         {
             _userDAO.UpdateUserName(airlineUser.User_Name, airline.User_Name);
             _airlineDAO.Update(airline);
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Admin: {token.User.User_Name} Tried To Update Details For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", true);
         }
         else
         {
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Admin: {token.User.User_Name} Tried To Update Details For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", false);
             throw new UserNotExistException($"Sorry, But '{airline.User_Name}' Does Not Exist.");
         }
     }
     else
     {
         _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Updates, $"Anonymous User Tried To Update Details For Some Airline Company. Id: {airline.Id} ({airline.User_Name}).", false);
     }
 }
 // Remove Some Airline Company.
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     if (UserIsValid(token) && airline != null)
     {
         User airlineUser = _userDAO.GetUserById(airline.Id);
         if (airlineUser != null)
         {
             _airlineDAO.Remove(airline);
             _userDAO.RemoveUserName(airlineUser);
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Deletions, $"Admin {token.User.User_Name} Tried Delete Some Admin. Id: {airline.Id} ({airline.User_Name}).", true);
         }
         else
         {
             _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Deletions, $"Admin {token.User.User_Name} Tried Delete Some Admin. Id: {airline.Id} ({airline.User_Name}).", false);
             throw new UserNotExistException($"Sorry, But '{airline.User_Name}' Does Not Exist.");
         }
     }
     else
     {
         _backgroundDAO.AddNewAction(Categories.AirlineCompanies | Categories.Deletions, $"Anonymous User Tried Delete Some Airline Comapny. Id: {airline.Id} ({airline.User_Name}).", false);
     }
 }
コード例 #10
0
        public UserType TryLogin(string userName, string password, out ILogin token, out FacadeBase facade)
        {
            token  = null;
            facade = new AnonymousUserFacade();

            // Default Admin.
            if (userName.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
            {
                if (password.ToUpper() == FlyingCenterConfig.ADMIN_PASSWORD.ToUpper())
                {
                    token = new LoginToken <Administrator>
                    {
                        User = new Administrator
                               (
                            0, //Admin Number
                            0, //Id
                            FlyingCenterConfig.ADMIN_NAME,
                            FlyingCenterConfig.ADMIN_PASSWORD
                               )
                    };
                    facade = new LoggedInAdministratorFacade();
                    return(UserType.Administrator);
                }
                else
                {
                    throw new WrongPasswordException("Sorry, But Your Password Isn't Match To Your User Name.");
                }
            }

            // DAO Users.
            User user = _userDAO.GetUserByUserName(userName);

            if (user != null)
            {
                if (user.User_Name == userName)
                {
                    if (password.ToUpper() == user.Password.ToUpper())
                    {
                        switch (user.MyType)
                        {
                        case UserType.Administrator:
                        {
                            Administrator admin = _administratorDAO.GetById(user.Id);
                            token = new LoginToken <Administrator>
                            {
                                User = new Administrator
                                       (
                                    admin.Admin_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password
                                       )
                            };
                            facade = new LoggedInAdministratorFacade();
                            return(UserType.Administrator);
                        }

                        case UserType.Airline:
                        {
                            AirlineCompany airline = _airlineDAO.GetById(user.Id);
                            token = new LoginToken <AirlineCompany>
                            {
                                User = new AirlineCompany
                                       (
                                    airline.Airline_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password,
                                    airline.Airline_Name,
                                    airline.Country_Code
                                       )
                            };
                            facade = new LoggedInAirlineFacade();
                            return(UserType.Airline);
                        }

                        case UserType.Customer:
                        {
                            Customer customer = _customerDAO.GetById(user.Id);
                            token = new LoginToken <Customer>
                            {
                                User = new Customer
                                       (
                                    customer.Customer_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password,
                                    customer.First_Name,
                                    customer.Last_Name,
                                    customer.Address,
                                    customer.Phone_No,
                                    customer.Credit_Card_Number
                                       )
                            };
                            facade = new LoggedInCustomerFacade();
                            return(UserType.Customer);
                        }

                        default:
                        {
                            return(UserType.Anonymous);
                        }
                        }
                    }
                    else
                    {
                        throw new WrongPasswordException("Sorry, But Your Password Is Not Match To Your User Name.");
                    }
                }
                else
                {
                    throw new UserNotExistException($"Sorry, But {userName} Does Not Exist.");
                }
            }
            return(UserType.Anonymous);
        }
コード例 #11
0
        // This Function Override The Real Function Equals And Compair Between This.Id And Other.Id.
        public override bool Equals(object obj)
        {
            AirlineCompany otherAirline = obj as AirlineCompany;

            return(this.Id == otherAirline.Id);
        }