public async Task <ActionResult <Customer> > GetCustomerById(int customerid)
        {
            AnonymousUserFacade facade = new AnonymousUserFacade(false);

            Customer result = null;

            try
            {
                result = await Task.Run(() => facade.GetCustomerById(customerid));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, $"{{ error: can't get customer by id \"{ex.Message}\" }}"));
            }
            if (result == null)
            {
                return(StatusCode(204, "{No customer by this id. }"));
            }
            return(Ok(result));
        }
Esempio n. 2
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());
        }