Exemplo n.º 1
0
        public void UPDATE_AIRLINECOMPANY()
        {
            bool         actual = false;
            LoginService ls     = new LoginService();
            LoginToken <Administrator> ltAdmin = null;
            bool res = ls.TryAdminLogin("9999", "admin", out ltAdmin);

            if (res == true)
            {
                FlyingCenterSystem           fs       = FlyingCenterSystem.Instance;
                ILoggedInAdministratorFacade iAdminFS = fs.GetFacade <ILoggedInAdministratorFacade>();
                AirLineCompany airLineComp            = new AirLineCompany();
                airLineComp.airLineName = "BramnikAirLineCompany";
                airLineComp.userName    = "******";
                airLineComp.password    = "******";
                airLineComp.id          = 1;
                airLineComp.countryCode = 1;
                iAdminFS.UpdateAirLineDetails(ltAdmin, airLineComp);
                if (airLineComp == iAdminFS.GetAirLineCompanyById(ltAdmin, 1))
                {
                    actual = true;
                }
                Assert.IsTrue(actual);
            }
        }
Exemplo n.º 2
0
        // Create a random amount of airlines
        public void CreateRandomAirlineCompanies(int numberOfAirlines)
        {
            Country               randomCountry = new Country();
            IList <Country>       dbCountries   = adminF.GetAllCountries(adminT);
            List <AirLineCompany> airlines      = new List <AirLineCompany>();
            Random random = new Random();

            for (int i = 0; i < numberOfAirlines; i++)
            {
                randomCountry = dbCountries[random.Next(0, dbCountries.Count)];
                AirLineCompany c = new AirLineCompany
                {
                    AirLineName = RandomString(true),
                    UserName    = RandomString(true),
                    Password    = RandomPassword(),
                    CountryCode = randomCountry.ID,
                };
                foreach (AirLineCompany airLine in airlines)
                {
                    if (airLine.UserName == c.UserName || airLine.Password == c.Password || adminF.GetAirlineUserName(adminT, c.UserName) == c.UserName)
                    {
                        i--;
                    }
                }
                airlines.Add(c);
                adminF.CreateNewAirline(adminT, c);
            }
        }
        public AirLineCompany Get(int id)
        {
            SQLConnectionOpen();
            AirLineCompany comp = null;
            string         str  = $"SELECT * FROM AirlineCompanies WHERE ID = {id}";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        reader.Read();
                        comp = new AirLineCompany
                        {
                            id          = (int)reader["ID"],
                            airLineName = (string)reader["AIRLINE_NAME"],
                            userName    = (string)reader["USER_NAME"],
                            password    = (string)reader["PASSWORD"],
                            countryCode = (int)reader["COUNTRY_CODE"]
                        };
                    }
                }
            }
            SQLConnectionClose();
            return(comp);
        }
Exemplo n.º 4
0
        public List <Flight> GetFlightsByAirLineCompany(AirLineCompany company)
        {
            SQLConnectionOpen();
            List <Flight> flByOriginCountry = new List <Flight>();
            Flight        fl  = null;
            string        str = $"SELECT* FROM Flights WHERE AIRLINECOMPANY_ID = {company.id}";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        fl = new Flight
                        {
                            id = (int)reader["ID"],
                            airLineCompanyId       = (int)reader["AIRLINECOMPANY_ID"],
                            originCountryCode      = (int)reader["ORIGIN_COUNTRY_CODE"],
                            destinationCountryCode = (int)reader["DESTINATION_COUNTRY_CODE"],
                            departureTime          = (DateTime)reader["DEPARTURE_TIME"],
                            landingTime            = (DateTime)reader["LANDING_TIME"],
                            remainingTickets       = (int)reader["REMAINING_TICKETS"],
                            flightStatusId         = (int)reader["FLIGHT_STATUS_ID"],
                        };
                        flByOriginCountry.Add(fl);
                    }
                }
            }
            SQLConnectionClose();
            return(flByOriginCountry);
        }
        private void DictionarysFilling()
        {
            SQLConnectionOpen();
            string str = "SELECT * FROM AirlineCompanies";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        AirLineCompany comp = new AirLineCompany
                        {
                            id          = (int)reader["ID"],
                            airLineName = (string)reader["AIRLINE_NAME"],
                            userName    = (string)reader["USER_NAME"],
                            password    = (string)reader["PASSWORD"],
                            countryCode = (int)reader["COUNTRY_CODE"]
                        };
                        //  idAiLineCompanyDict.Add(comp.id,comp);
                        //  userNameCompanyDict.Add(comp.userName, comp);
                    }
                }
            }
            SQLConnectionClose();
        }
        public List <Ticket> GetTicketsByAirLineCompany(AirLineCompany comp)
        {
            SQLConnectionOpen();
            List <Ticket> ticketsListByAirLine = new List <Ticket>();
            string        str = $"SELECT Tickets.ID,Tickets.FLIGHT_ID,Tickets.CUSTOMER_ID FROM Tickets JOIN Flights ON Tickets.FLIGHT_ID = Flights.ID WHERE Flights.AIRLINECOMPANY_ID  = {comp.id}";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Ticket ticket = new Ticket
                        {
                            id         = (int)reader["ID"],
                            customerId = (int)reader["CUSTOMER_ID"],
                            flightId   = (int)reader["FLIGHT_ID"]
                        };
                        ticketsListByAirLine.Add(ticket);
                    }
                }
            }
            SQLConnectionClose();
            return(ticketsListByAirLine);
        }
        public List <AirLineCompany> GetAllAirLinesCompanyByCountry(Country country)
        {
            SQLConnectionOpen();
            List <AirLineCompany> compList = new List <AirLineCompany>();
            string str = $"SELECT * FROM AirlineCompanies WHERE COUNTRY_CODE = '{country.id}'";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        AirLineCompany comp = new AirLineCompany
                        {
                            id          = (int)reader["ID"],
                            airLineName = (string)reader["AIRLINE_NAME"],
                            userName    = (string)reader["USER_NAME"],
                            password    = (string)reader["PASSWORD"],
                            countryCode = (int)reader["COUNTRY_CODE"]
                        };
                        compList.Add(comp);
                    }
                }
            }
            SQLConnectionClose();
            return(compList);
        }
Exemplo n.º 8
0
        public IList <Flight> GetAllFlightsByAirLineCompanies(AirLineCompany comp)
        {
            IList <Flight> allFlightsByAirLine = new List <Flight>();

            allFlightsByAirLine = _flightDAO.GetFlightsByAirLineCompany(comp);
            return(allFlightsByAirLine);
        }
Exemplo n.º 9
0
        public void REMOVE_AIRLINECOMPANY()
        {
            bool         actual = false;
            LoginService ls     = new LoginService();
            LoginToken <Administrator> ltAdmin = null;
            bool res = ls.TryAdminLogin("9999", "admin", out ltAdmin);

            if (res == true)
            {
                FlyingCenterSystem           fs       = FlyingCenterSystem.Instance;
                ILoggedInAdministratorFacade iAdminFS = fs.GetFacade <ILoggedInAdministratorFacade>();
                AirLineCompany airLineComp            = new AirLineCompany();
                airLineComp.airLineName = "BramnikAirLineCompany";
                airLineComp.userName    = "******";
                airLineComp.password    = "******";
                airLineComp.id          = 1;
                airLineComp.countryCode = 1;
                iAdminFS.RemoveAirLine(ltAdmin, airLineComp);
                if (iAdminFS.CheckIfAirlinesTableIsEmpty(ltAdmin))
                {
                    actual = true;
                }

                Assert.IsTrue(actual);
            }
        }
Exemplo n.º 10
0
        public IHttpActionResult ConfirmEmail([FromUri] string guid)
        {
            ConfirmedUser user = null;

            FCS = FlyingCenterSystem.GetInstance();
            IAnonymousUserFacade af = FCS.GetFacade(null) as AnonymousUserFacade;

            user = af.ConfirmMyEmail(guid);

            if (user.UserName == null)
            {
                return(NotFound());
            }
            if (user.EmailCon == "was already confirmed")
            {
                return(Ok(user.EmailCon));
            }
            if (user.Type == "customer")
            {
                Customer newCustomer = Redis.RedisGetCustomer("localhost", user.UserName);
                newCustomer.ID = af.AddCustomerToData(newCustomer);

                return(Ok($"{user.UserName} was confirmed"));
            }

            AirLineCompany airline = Redis.RedisGetAirline("localhost", user.UserName);

            return(Ok($"{user.UserName} was confirmed one of our admins will get back to you. thank you!"));
        }
Exemplo n.º 11
0
        public IHttpActionResult CreateNewAirline(AirLineCompany airlineCompany)
        {
            FCS = FlyingCenterSystem.GetInstance();
            ILoggedInAdministratorFacade adminiFacade = FCS.GetFacade(adminT) as ILoggedInAdministratorFacade;
            long airlineCompanyId = adminiFacade.CreateNewAirline(adminT, airlineCompany);

            //airlineCompany = adminiFacade.GetAirlineCompanyById(adminT, airlineCompanyId);
            return(CreatedAtRoute("createairlinecompany", new { id = airlineCompanyId }, airlineCompany));
        }
Exemplo n.º 12
0
        public AirLineCompany CreateNewTestAirlineCompany()
        {
            Country testCountry = new Country("isreal");

            testCountry.ID = adminF.CreateNewCountry(adminT, testCountry);
            AirLineCompany testAirline = new AirLineCompany("elal", "elal", "4321", testCountry.ID);

            adminF.CreateNewAirline(adminT, testAirline);
            return(testAirline);
        }
Exemplo n.º 13
0
        // adding a new airline information to redis
        public static bool RedisSaveNewAirline(string host, string key, AirLineCompany value)
        {
            bool isSuccess = false;

            using (RedisClient redisClient = new RedisClient(host))
            {
                if (redisClient.Get <AirLineCompany>(key) == null)
                {
                    isSuccess = redisClient.Set(key, value);
                    //redisClient.Remove(key);
                }
            }
            return(isSuccess);
        }
Exemplo n.º 14
0
        public void GetAllAirLineCompanies()
        {
            FlyingCenterSystem     fs         = FlyingCenterSystem.Instance;
            IAnonymousUserFacade   iAnonym    = fs.GetFacade <IAnonymousUserFacade>();
            IList <AirLineCompany> list       = iAnonym.GetAllAirLineCompanies();
            AirLineCompany         comp1      = new AirLineCompany(1, "BramnikAirLineCompany", "BramnikAdmin", "bramnik", 1);
            AirLineCompany         comp2      = new AirLineCompany(2, "KramnikAirLineCompany", "KramnikAdmin", "kramnik", 1);
            List <AirLineCompany>  originList = new List <AirLineCompany>()
            {
                comp1, comp2
            };
            bool actual = list.SequenceEqual(originList);

            Assert.IsTrue(actual);
        }
Exemplo n.º 15
0
        public TestInfo()
        {
            ClearDB();
            FC     = FlyingCenterSystem.GetInstance();
            adminT = (LoginToken <Administrator>)FC.Login(FlightCenterConfig.ADMIN_NAME, FlightCenterConfig.ADMIN_PASSWORD);
            adminF = (LoggedInAdministratorFacade)FC.GetFacade(adminT);
            Customer customer = CreateNewTestCustomer();

            customerT = (LoginToken <Customer>)FC.Login(customer.UserName, customer.Password);
            customerF = (LoggedInCustomerFacade)FC.GetFacade(customerT);
            AirLineCompany airlineCompany = CreateNewTestAirlineCompany();

            airlineT   = (LoginToken <AirLineCompany>)FC.Login(airlineCompany.UserName, airlineCompany.Password);
            airlineF   = (LoggedInAirlineFacade)FC.GetFacade(airlineT);
            anonymousF = (AnonymousUserFacade)FC.GetFacade(null);
        }
Exemplo n.º 16
0
        public void TestNoMoreTicketsException()
        {
            test = new TestInfo();
            Country testCountry  = new Country("usa");
            Country testCountry2 = new Country("russia");

            testCountry.ID  = test.adminF.CreateNewCountry(test.adminT, testCountry);
            testCountry2.ID = test.adminF.CreateNewCountry(test.adminT, testCountry2);
            AirLineCompany a = new AirLineCompany("amrican", "amrican", "12345", testCountry.ID);

            a.ID = test.adminF.CreateNewAirline(test.adminT, a);
            Flight         flight = new Flight(a.ID, testCountry.ID, testCountry2.ID, DateTime.ParseExact("2019-07-08 12:00:00", "yyyy-MM-dd HH:mm:ss", null), DateTime.ParseExact("2019-07-18 12:00:00", "yyyy-MM-dd HH:mm:ss", null), 0);
            FlightDAOMSSQL Fdao   = new FlightDAOMSSQL();

            flight.ID = Fdao.ADD(flight);
            test.customerF.PurchaseTicket(test.customerT, flight);
        }
        public void Remove(AirLineCompany ob)
        {
            int            id   = ob.id;
            AirLineCompany comp = Get(ob.id);

            if (comp is null)
            {
                throw new AirLineCompanyNotExistException("This company not exist");
            }
            SQLConnectionOpen();
            string str = $"DELETE FROM AirlineCompanies WHERE ID = {id}";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                cmd.ExecuteNonQuery();
            }
            SQLConnectionClose();
        }
        public void Update(AirLineCompany ob)
        {
            AirLineCompany comp = Get(ob.id);

            if (comp is null)
            {
                throw new AirLineCompanyNotExistException("This company not exist");
            }
            AirLineCompany oldAirLineComp = Get(ob.id);

            SQLConnectionOpen();
            string str = $"UPDATE AirlineCompanies SET AIRLINE_NAME = '{ob.airLineName}',USER_NAME = '{ob.userName}',PASSWORD = '******',COUNTRY_CODE = {ob.countryCode} WHERE ID = {ob.id}";

            using (SqlCommand cmd = new SqlCommand(str, con))
            {
                cmd.ExecuteNonQuery();
            }
            SQLConnectionClose();
        }
Exemplo n.º 19
0
        public IHttpActionResult AddNewAirlineToRedis([FromBody] AirLineCompany airline)
        {
            bool redisBool = false;

            //var jsonStringAccount = Newtonsoft.Json.JsonConvert.SerializeObject(airline);
            redisBool = Redis.RedisSaveNewAirline("localhost", airline.UserName, airline);
            FCS       = FlyingCenterSystem.GetInstance();
            IAnonymousUserFacade af = FCS.GetFacade(null) as AnonymousUserFacade;

            if (redisBool == false)
            {
                return(NotFound());
            }
            guideForAuth = Guid.NewGuid().ToString();
            NewUser airlinerUser = new NewUser {
                UserNAME = airline.UserName, Email = airline.Email, Guid = guideForAuth, Type = "airline"
            };

            af.AddNewUser(airlinerUser);
            SendEmail(airline.Email, airline.AirLineName, guideForAuth);
            return(Ok(redisBool));
        }
Exemplo n.º 20
0
        // Create a random amount of flights
        public void CreateRandomFlights(int randomNum)
        {
            Random                 random         = new Random();
            Country                randomCountry  = new Country();
            Country                randomCountry2 = new Country();
            AirLineCompany         randomAirline  = new AirLineCompany();
            List <Flight>          flights        = new List <Flight>();
            IList <Country>        dbCountries    = adminF.GetAllCountries(adminT);
            IList <AirLineCompany> dbAirlines     = adminF.GetAllAirlineCompanies();

            for (int i = 0; i < randomNum; i++)
            {
                randomCountry = dbCountries[random.Next(0, dbCountries.Count)];
                randomAirline = dbAirlines[random.Next(0, dbAirlines.Count)];
                dbCountries.Remove(randomCountry);
                randomCountry2 = dbCountries[random.Next(0, dbCountries.Count)];
                Flight flight = new Flight
                {
                    AirLineCompanyID       = randomAirline.ID,
                    OriginCountryCode      = randomCountry.ID,
                    DestinationCountryCode = randomCountry2.ID,
                    DepartureTime          = DateTime.Now,
                    LandingTime            = DateTime.Now,
                    RemaniningTickets      = random.Next(0, 200),
                };
                foreach (Flight f in flights)
                {
                    if (f.OriginCountryCode == flight.OriginCountryCode && f.DestinationCountryCode == flight.DestinationCountryCode)
                    {
                        i--;
                    }
                    else
                    {
                        flights.Add(flight);
                    }
                }
            }
        }
        public int Add(AirLineCompany ob)
        {
            int            res  = 0;
            AirLineCompany comp = GetAirLineCompanyByName(ob.airLineName);

            if (comp is null)
            {
                SQLConnectionOpen();
                string str = $"INSERT INTO AirlineCompanies VALUES('{ob.airLineName}','{ob.userName}','{ob.password}',{ob.countryCode});SELECT SCOPE_IDENTITY()";
                using (SqlCommand cmd = new SqlCommand(str, con))
                {
                    res = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            else
            {
                throw new AirLineCompanyAlreadyExistException("Such Airline Company already exist");
            }
            // idAiLineCompanyDict.Add(id,ob);
            // userNameCompanyDict.Add(userName, ob);
            SQLConnectionClose();
            return(res);
        }
Exemplo n.º 22
0
        public bool TryAirLineLogin(string password, string userName, out LoginToken <AirLineCompany> loginToken)
        {
            bool res = false;

            loginToken = null;
            AirLineCompany comp = null;

            _airLineDAO = new AirLineDAOMSSQL();
            comp        = _airLineDAO.GetAirLineByUserName(userName);
            if (!(comp is null))
            {
                if (comp.password != password)
                {
                    throw new WrongPasswordException("entered password is not correct");
                }
                else
                {
                    loginToken      = new LoginToken <AirLineCompany>();
                    loginToken.User = comp;
                    res             = true;
                }
            }
            return(res);
        }
 public void ModifyAirLineDetails(LoginToken <AirLineCompany> token, AirLineCompany airline)
 {
     _airLineDAO.Update(airline);
 }
Exemplo n.º 24
0
        public int CreateNewairLine(LoginToken <Administrator> token, AirLineCompany comp)
        {
            int res = _airLineDAO.Add(comp);

            return(res);
        }
Exemplo n.º 25
0
 public void UpdateAirLineDetails(LoginToken <Administrator> token, AirLineCompany comp)
 {
     _airLineDAO.Update(comp);
 }
Exemplo n.º 26
0
 public void RemoveAirLine(LoginToken <Administrator> token, AirLineCompany comp)
 {
     _airLineDAO.Remove(comp);
 }