Beispiel #1
0
        public List <AirlineCompanies> GetAll()
        {
            List <AirlineCompanies> ac_list = new List <AirlineCompanies>();

            try
            {
                using (var conn = new NpgsqlConnection(GlobalConfig.GetConn))
                {
                    conn.Open();
                    string        sp_name = "sp_get_all_airlinecomapnies";
                    NpgsqlCommand command = new NpgsqlCommand(sp_name, conn);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        AirlineCompanies ac = new AirlineCompanies();
                        {
                            ac.Name      = (string)reader["name"];
                            ac.ID        = (long)reader["id"];
                            ac.CountryId = (long)reader["country_id"];
                            ac.UserId    = (long)reader["user_id"];
                        }
                        ac_list.Add(ac);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error($"Something went wrong in GetAll AirlineCompanies {ex} check connection");
            }
            return(ac_list);
        }
Beispiel #2
0
        public AirlineCompanies GetById(long id)
        {
            AirlineCompanies ac = new AirlineCompanies();

            try
            {
                using (var conn = new NpgsqlConnection(GlobalConfig.GetConn))
                {
                    conn.Open();

                    using (var cmd = new NpgsqlCommand("sp_get_airlinecompanies_by_id", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add(new NpgsqlParameter("x", id));

                        var reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            ac.Name      = (string)reader["name"];
                            ac.ID        = (long)reader["id"];
                            ac.CountryId = (long)reader["country_id"];
                            ac.UserId    = (long)reader["user_id"];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error($"Something went wrong in GetAirlineCompaniesById {ex} check connection");
            }
            return(ac);
        }
Beispiel #3
0
 public void CreateNewAirline(LoginToken <Administrator> token, AirlineCompanies airline)
 {
     if (token != null)
     {
         if (_airlineDAO != null)
         {
             _airlineDAO.Add(airline);
         }
         else
         {
             _airlineDAO = new AirlineCompaniesDAOPGSQL();
             _airlineDAO.Add(airline);
         }
     }
 }
Beispiel #4
0
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompanies airline)
 {
     if (token != null)
     {
         if (_airlineDAO != null)
         {
             _airlineDAO.Update(airline);
         }
         else
         {
             _airlineDAO = new AirlineCompaniesDAOPGSQL();
             _airlineDAO.Update(airline);
         }
     }
 }
Beispiel #5
0
 public void ModifyAirlineDetails(LoginToken <AirlineCompanies> token, AirlineCompanies airline)
 {
     if (token != null)
     {
         if (_airlineDAO != null)
         {
             _airlineDAO.Update(airline);
         }
         else
         {
             _airlineDAO = new AirlineCompaniesDAOPGSQL();
             _airlineDAO.Update(airline);
         }
     }
 }
Beispiel #6
0
        public AirlineCompanies GetAirlineById(LoginToken <Administrator> token, int id)
        {
            AirlineCompanies air = new AirlineCompanies();

            if (token != null)
            {
                if (_airlineDAO != null)
                {
                    air = _airlineDAO.GetById(id);
                }
                else
                {
                    _airlineDAO = new AirlineCompaniesDAOPGSQL();
                    air         = _airlineDAO.GetById(id);
                }
            }
            return(air);
        }
Beispiel #7
0
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompanies airline)
 {
     if (token != null)
     {
         if (token.User.Level >= 2)
         {
             if (_airlineDAO != null)
             {
                 _airlineDAO.Remove(airline.ID);
             }
             else
             {
                 _airlineDAO = new AirlineCompaniesDAOPGSQL();
                 _airlineDAO.Remove(airline.ID);
             }
         }
         else
         {
             Console.WriteLine("Your level of administration is too low,you must be level 2 or higher");
         }
     }
 }
        public override bool Equals(object obj)
        {
            AirlineCompanies other = (AirlineCompanies)obj;

            return(this.ID == other.ID);
        }
Beispiel #9
0
 public void Add(AirlineCompanies ac)
 {
     ExecuteNonQuery($"call sp_add_airlinecompanies('{ac.Name}',{ac.CountryId},{ac.UserId})");
     log.Info($"New Airline has added {ac}");
 }
Beispiel #10
0
 public void Update(AirlineCompanies ac)
 {
     ExecuteNonQuery($"call sp_update_airlinecompany({ac.ID},{ac.Name},{ac.CountryId},{ac.UserId})");
 }
Beispiel #11
0
        public bool TryLogin(string userName, string password, out LoginToken <IUser> token, out FacadeBase facade)
        {
            token = new LoginToken <IUser>();
            List <Users> users = _userDAO.GetAll();

            try
            {
                if (userName != "admin" && password != "9999")
                {
                    for (int i = 0; i < users.Count; i++)
                    {
                        if (users[i].UserName == userName && users[i].Password == password)
                        {
                            if (users[i].UserRole == 1)
                            {
                                List <Administrator> administrators = _adminDAO.GetAll();
                                for (int b = 0; b < administrators.Count; b++)
                                {
                                    if (administrators[b].User_id == users[i].ID)
                                    {
                                        Administrator admin = administrators[b];
                                        admin.User = users[i];
                                        token.User = admin;
                                        facade     = new LoggedInAdministratorFacade();
                                        return(true);
                                    }
                                }
                            }
                            else if (users[i].UserRole == 2)
                            {
                                List <AirlineCompanies> airCompanies = _arilineDAO.GetAll();
                                for (int b = 0; b < airCompanies.Count; b++)
                                {
                                    if (airCompanies[b].UserId == users[i].ID)
                                    {
                                        AirlineCompanies air = airCompanies[b];
                                        air.User   = users[i];
                                        token.User = air;
                                        facade     = new LoggedInAirlineFacade();
                                        return(true);
                                    }
                                }
                            }
                            else if (users[i].UserRole == 3)
                            {
                                List <Customers> customers = _customerDAO.GetAll();
                                for (int b = 0; b < customers.Count; b++)
                                {
                                    if (customers[b].UserId == users[i].ID)
                                    {
                                        Customers cus = customers[b];
                                        cus.User   = users[i];
                                        token.User = cus;
                                        facade     = new LoggedInCustomerFacade();
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Administrator a = new Administrator();
                    token.User = a;
                    facade     = new LoggedInAdministratorFacade();
                }
            }
            catch (WrongCredentialsException ex)
            {
                log.Error($"Wrong credentials... Try again {ex}");
            }
            token  = null;
            facade = new AnonymousUserFacade();
            return(false);
        }