public void MofidyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline) { if (token != null) { _airlineDAO.Update(airline); } else { logger.Error("Error - token is null"); throw new NullTokenException("There is a problem to mofidy airline details. Please check your login details.Token is null."); } }
public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline) { if (token != null) { if (token.User.Level == 2 || token.User.Level == 3) { _airlineDAO.Remove(airline); } else { logger.Debug("This administrator level is not authorized to remove airline."); throw new WrongLevelOfAccessException("Access is denied. You have no authorization to remove airline."); } } else { logger.Error("Error - token is null"); throw new NullTokenException("There is a problem to remove airline. Access is denied."); } }
public AirlineCompany GetById(int id) { AirlineCompany result = null; using (NpgsqlCommand cmd = new NpgsqlCommand()) { using (cmd.Connection = new NpgsqlConnection(m_conn_string)) { cmd.Connection.Open(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = $"select * from sp_get_airline_by_id({id})"; NpgsqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { result = new AirlineCompany { Id = (int)reader["id"], Name = reader["name"].ToString(), Country_Id = (int)reader["country_id"], User_Id = (int)reader["user_id"] }; result.user = new User { Id = (int)reader["id"], Username = reader["username"].ToString(), Password = reader["password"].ToString(), Email = reader["email"].ToString(), User_Role = (int)reader["user_role"] }; } } } //UserDAOPGSQL userDAOPGSQL = new UserDAOPGSQL(); //result.user = userDAOPGSQL.GetById(result.User_Id); return(result); }
public void Add(AirlineCompany a) { ExecuteNonQuery($"call sp_insert_airline('{a.Name}', {a.Country_Id}, {a.User_Id});"); }
public void Update(AirlineCompany airline) { int result = ExecuteNonQuery($"call sp_update_airline( {airline.Id}, '{airline.Name}', {airline.Country_Id}, {airline.User_Id})"); }
public void Remove(AirlineCompany airline) { int result = ExecuteNonQuery($"call sp_delete_airline_company ({airline.Id})"); }
public bool TryLogin(string userName, string password, out ILoginToken token) { token = null; if (userName == "admin" && password == "9999") { logger.Info("Super administrator logged in."); token = new LoginToken <Administrator>(); return(true); } else { try { User user; try { user = _userDAO.GetUserByUsername(userName); } catch (Exception e) { logger.Fatal("Wrong username. Please try again.", e); return(false); } if (user.Password == password) { if (user.User_Role == 1) { Administrator admin = _adminDAO.GetById(user.Id); admin.user = user; token = new LoginToken <Administrator>() { User = admin }; } if (user.User_Role == 2) { AirlineCompany airline = _airlineDAO.GetAirlineByUsername(user.Username); //TODO check if null airline.user = user; token = new LoginToken <AirlineCompany>() { User = airline }; } if (user.User_Role == 3) { Customer customer = _customerDAO.GetCustomerByUsername(user.Username); customer.user = user; token = new LoginToken <Customer>() { User = customer }; } logger.Info("Login was completed. Username and password are correct."); return(true); } else { logger.Error("Login failed. Username or password are incorrect."); throw new WrongCredentialsException("Username or password are incorrect. Please try again."); } } catch (Exception e) { Console.WriteLine(e); logger.Error("Login failed.", e); return(false); } //log4net } }