public IHttpActionResult GetCountryById([FromUri] int id)
        {
            IHttpActionResult result = controllersCenter.ExecuteSafe(() =>
            {
                Country country = facade.GetCountryById(id);
                return(GetSuccessResponse(country, "No Country Found With ID That Recived..."));
            });

            return(result); // for debug - break point here
        }
Ejemplo n.º 2
0
        public IActionResult GetCountryById([FromQuery] int countryId)
        {
            IActionResult result = SafeExecute(() =>
            {
                Country country = AnonymousUserFacade.GetCountryById(countryId);
                return(SingleResultChecker(country, "No coutry with this ID was found."));
            });

            return(result);
        }
Ejemplo n.º 3
0
        public ActionResult RequestAddingAirline()
        {
            //getting info from the form
            string inputUsername    = Request.Form["inputUsername"];
            string inputPassword    = Request.Form["inputPassword"];
            string inputAirlineName = Request.Form["inputAirlineName"];
            string inputCountryId   = Request.Form["inputCountryId"];

            //create list if there isn't any yet
            if (RedisAccessLayer.GetWithTimeStamp("airlineRequestList") == null)
            {
                List <string> airlineRequestList = new List <string>();
                string        aRL = JsonConvert.SerializeObject(airlineRequestList);
                RedisAccessLayer.SaveWithTimeStamp("airlineRequestList", aRL);
            }

            //getting the list
            string        serializedRequestList = RedisAccessLayer.GetWithTimeStamp("airlineRequestList").JsonData;
            List <object> requestList           = JsonConvert.DeserializeObject <List <object> >(serializedRequestList);

            Country country = anonymousFacade.GetCountryById(long.Parse(inputCountryId));

            var airlineRequest = new //creating the item
            {
                Username    = inputUsername,
                Password    = inputPassword,
                AirlineName = inputAirlineName,
                CountryId   = inputCountryId,
                Country     = country.CountryName
            };

            //putting the item in the list
            requestList.Add(airlineRequest);

            //serialize back into redis
            string finishedRequestList = JsonConvert.SerializeObject(requestList);

            RedisAccessLayer.SaveWithTimeStamp("airlineRequestList", finishedRequestList);

            return(Redirect("http://localhost:9002/")); //returning the login screen
        }
Ejemplo n.º 4
0
        public IHttpActionResult Login([FromBody] JObject credentials, long flightId = -1)
        {
            string username = credentials["username"].Value <string>();
            string password = credentials["password"].Value <string>();

            FacadeBase facade = null;

            try
            {
                facade = fcs.Login(username, password, out ILoginToken loginToken);


                if (facade != null)
                {
                    IAnonymousUserFacade anonFacade = new AnonymousUserFacade();
                    //IMPROVE THIS! enum? dictionary? isn't it longer? switch case?
                    if (facade is ILoggedInCustomerFacade)
                    {
                        //FOR CUSTOMERS ONLY: make use of the query parameter to get the flight and return it

                        LoginToken <Customer> custToken = loginToken as LoginToken <Customer>;
                        Customer c = anonFacade.GetCustomerById(custToken.User.ID);

                        //DO LIKE THIS:
                        var res = "{" + $"\"type\":\"Customer\",\"id\":\"{c.ID}\",\"firstName\":\"{c.FirstName}\",\"lastName\":\"{c.LastName}\",\"userName\":\"{c.UserName}\",\"password\":\"{c.Password}\",\"address\":\"{c.Address}\",\"phoneNo\":\"{c.PhoneNo}\",\"creditCardNumber\":\"{c.CreditCardNumber}\",\"flightId\":\"{flightId}\"" + "}";
                        return(Ok <string>(res));
                        //return Ok<string>("Customer");
                    }

                    if (facade is ILoggedInAirlineFacade)
                    {
                        LoginToken <AirlineCompany> airlineToken = loginToken as LoginToken <AirlineCompany>;
                        AirlineCompany a = anonFacade.GetAirlineCompanyById(airlineToken.User.ID);

                        Country c = anonFacade.GetCountryById(a.CountryCode);

                        //DO LIKE THIS:
                        var res = "{" + $"\"type\":\"Airline\",\"id\":\"{a.ID}\",\"airlineName\":\"{a.AirlineName}\",\"userName\":\"{a.UserName}\",\"password\":\"{a.Password}\",\"countryCode\":\"{a.CountryCode}\",\"countryName\":\"{c.CountryName}\"" + "}";
                        return(Ok <string>(res));

                        //return Ok<string>("Airline");
                    }


                    if (facade is ILoggedInAdministratorFacade)
                    {
                        LoginToken <Administrator> custToken = loginToken as LoginToken <Administrator>;

                        //DO LIKE THIS:
                        var res = "{" + $"\"type\":\"Admin\",\"userName\":\"admin\",\"password\":\"9999\"" + "}";
                        return(Ok <string>(res));
                        //return Ok<string>("Admin");
                    }
                }
            }
            catch (WrongPasswordException e)
            {
                Console.WriteLine(e.Message);
            }
            return(Unauthorized());
        }