コード例 #1
0
        // Create New Flight For Current Airline.
        public long CreateFlight(LoginToken <AirlineCompany> token, Flight flight)
        {
            long newId = 0;

            if (UserIsValid(token) && flight != null)
            {
                if (token.User.Id != flight.AirlineCompany_Id)
                {
                    //ImHere_backgroundDAO.WriteRequestToLog(LogCategories.AirlineCompanies | LogCategories.Flights | LogCategories.Adds, $"Company: {token.User.UserName} Tried To Add New Flight (Flight: {flight.Id}).", false);
                    throw new FlightNotMatchException("The ID Of Your New Flight Isn't Match To Your Company ID");
                }
                if (flight.Departure_Time >= flight.Landing_Time)
                {
                    //ImHere_backgroundDAO.WriteRequestToLog(LogCategories.AirlineCompanies | LogCategories.Flights | LogCategories.Adds, $"Company: {token.User.UserName} Tried To Add New Flight (Flight: {flight.Id}).", false);
                    throw new DepartureTimeTooLateException("Departue Time Must Be Earlier Than Landing Time");
                }
                newId = _flightDAO.Add(flight);
                //ImHere_backgroundDAO.WriteRequestToLog(LogCategories.AirlineCompanies | LogCategories.Flights | LogCategories.Adds, $"Company: {token.User.UserName} Tried To Add New Flight (Flight: {flight.Id}).", true);
            }
            //else
            //ImHere_backgroundDAO.WriteRequestToLog(LogCategories.AirlineCompanies | LogCategories.Flights | LogCategories.Adds, $"Anonymous User Tried To Add Some Flight.", false);
            return(newId);
        }
コード例 #2
0
        public ReponseDetails CreateMessage(LoginToken <Customer> token, Message newMessage)
        {
            ReponseDetails response = new ReponseDetails();

            try
            {
                string error = null;
                if (UserIsValid(token))
                {
                    if (token.User.Id == newMessage.SenderId)
                    {
                        if (MessageIsValid(newMessage, out error))
                        {
                            response.ResponseMessage = _messageDAO.CreateMessage(newMessage);
                        }
                        else
                        {
                            response.ResponseMessage += "You're Message Is Invalid: " + error;
                        }
                    }
                    else
                    {
                        throw new UnauthorizedAccessException("Sorry But You're Unauthorized For This Action");
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseMessage += "Sent A Message Was Fail: " + ex.Message;
            }
            finally
            {
                //ImHere_backgroundDAO.WriteRequestToLog(LogCategories.Customers | LogCategories.Messages | LogCategories.Adds, $"Customer: {token.User.UserName} Tried To Sent A New Message (Message: {newMessage.Id}).", response.ResponseCode == Enum.ResponseCode.Success,newMessage.ToString(),response.ToString());
            }
            return(response);
        }
コード例 #3
0
 string IUserFacadeBase <Customer> .CreateMessage(LoginToken <Customer> login, Message newMessage)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
        public bool TryLogin(User userDetails, out ILogin token, out FacadeBase facade)
        {
            token  = null;
            facade = new AnonymousUserFacade();
            // Default Admin.
            if (userDetails.Type == UserTypes.Administrator && userDetails.UserName.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
            {
                if (userDetails.Password.ToUpper() == FlyingCenterConfig.ADMIN_PASSWORD.ToUpper())
                {
                    token = new LoginToken <IUser>
                    {
                        User = new Administrator
                               (
                            0, //Admin Number
                            0, //UserId
                            FlyingCenterConfig.ADMIN_NAME,
                            FlyingCenterConfig.ADMIN_PASSWORD
                               )
                    };
                    facade = new LoggedInAdministratorFacade();
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException("Sorry, But Your Password Isn't Match To Your User Name.");
                }
            }

            // DAO Users.
            User user = _userDAO.GetUserByUserName(userDetails.UserName);

            if (user != null)
            {
                if (user.UserName.ToUpper() == userDetails.UserName.ToUpper())
                {
                    if (userDetails.Password.ToUpper() == user.Password.ToUpper())
                    {
                        switch (userDetails.Type)
                        {
                        case UserTypes.Administrator:
                        {
                            Administrator admin = _administratorDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new Administrator
                                       (
                                    admin.AdminNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password
                                       )
                            };
                            facade = new LoggedInAdministratorFacade();
                            return(true);
                        }

                        case UserTypes.Airline:
                        {
                            AirlineCompany airline = _airlineDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new AirlineCompany
                                       (
                                    airline.AirlineNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password,
                                    airline.AirlineName,
                                    airline.CountryCode
                                       )
                            };
                            facade = new LoggedInAirlineFacade();
                            return(true);
                        }

                        case UserTypes.Customer:
                        {
                            Customer customer = _customerDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new Customer
                                       (
                                    customer.CustomerNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password,
                                    customer.FirstName,
                                    customer.LastName,
                                    customer.Address,
                                    customer.PhoneNo,
                                    customer.CreditCardNumber
                                       )
                            };
                            return(true);
                        }

                        default:
                            return(false);
                        }
                    }
                    else
                    {
                        throw new WrongPasswordException("Sorry, But Your Password Doe's Not Match To Your User Name.");
                    }
                }
                else
                {
                    throw new UserNotExistException($"Sorry, But {userDetails.UserName} Does Not Exist.");
                }
            }
            return(false);
        }