Exemplo n.º 1
0
        static void Main(string[] args)
        {
            PopulateDb();

            while (true)
            {
                if (currentUser == null)
                {
                    // I) prvo da izbere dali saka da se LOGIRA ili REGISTRIRA
                    //#####################################################
                    //Enter a number to choose one of the following:
                    // 1) Log In
                    // 2) Register
                    int userChoice = uiSrvc.LogInMenu();

                    //ako odbral da se logira LOGIN
                    //______________________________
                    if (userChoice == 1)
                    {
                        //treba da izbere vo koja uloga ke se logira
                        int      userRoleChoice = uiSrvc.RoleMenu();
                        UserRole role           = (UserRole)userRoleChoice;
                        Console.Clear();

                        //da vnese username i password za da se logira
                        Console.WriteLine("Enter username:"******"Enter password:"******"Enter first name:");
                        newUser.FirstName = Console.ReadLine();
                        Console.WriteLine("Enter last name:");
                        newUser.LastName = Console.ReadLine();
                        Console.WriteLine("Enter username:"******"Enter password:"******"Account":
                    // mu se otvara sledniov izbor
                    // 1) Change Info,
                    // 2) Check Subscription,
                    // 3) Change password
                    int accountUserChoice = uiSrvc.AccountMenu(currentUser.Role);
                    Console.Clear();
                    // Change Info
                    if (accountUserChoice == 1)
                    {
                        Console.WriteLine("Enter new first name:");
                        string newFirstName = Console.ReadLine();
                        Console.WriteLine("Enter new last name:");
                        string newLastName = Console.ReadLine();

                        switch (currentUser.Role)
                        {
                        case UserRole.Standard:
                            standardUserSrvc.ChangeInfo(currentUser.Id, newFirstName, newLastName);
                            break;

                        case UserRole.Premium:
                            premiumUserSrvc.ChangeInfo(currentUser.Id, newFirstName, newLastName);
                            break;

                        case UserRole.Trainer:
                            trainerUserSrvc.ChangeInfo(currentUser.Id, newFirstName, newLastName);
                            break;
                        }
                    }
                    // Check Subscription
                    else if (accountUserChoice == 2)
                    {
                        Console.WriteLine($"Your subscription is {currentUser.Role}");
                        Console.ReadLine();
                    }
                    // Change password
                    else
                    {
                        Console.WriteLine("Enter old password");
                        string oldPassword = Console.ReadLine();
                        Console.WriteLine("Enter new password");
                        string newPassword = Console.ReadLine();
                        switch (currentUser.Role)
                        {
                        case UserRole.Standard:
                            standardUserSrvc.ChangePassword(currentUser.Id, oldPassword, newPassword);
                            break;

                        case UserRole.Premium:
                            premiumUserSrvc.ChangePassword(currentUser.Id, oldPassword, newPassword);
                            break;

                        case UserRole.Trainer:
                            trainerUserSrvc.ChangePassword(currentUser.Id, oldPassword, newPassword);
                            break;
                        }
                    }
                    break;

                case "Log Out":
                    currentUser = null;
                    break;

                case "Train":
                    //mu se pojavuva menito so izbor:
                    // 1) Video
                    // 2) Live
                    int userTrainingsChoice = 1;
                    if (currentUser.Role == UserRole.Premium)
                    {
                        userTrainingsChoice = uiSrvc.TrainingsMenu();
                    }
                    // -Video trainings:
                    if (userTrainingsChoice == 1)
                    {
                        int           videoTreiningItem = uiSrvc.TrainingMenuItems(videoTrainings.GetAllTrainings());
                        VideoTraining videoTraining     = videoTrainings.GetAllTrainings()[videoTreiningItem - 1];
                        Console.WriteLine(videoTraining.Title);
                        Console.WriteLine($"Link: {videoTraining.Link}");
                        Console.WriteLine($"Rating: {videoTraining.CheckRating()}");
                        Console.WriteLine($"Time: {videoTraining.Time} minutes.");
                        Console.ReadLine();
                    }
                    // -Live trainings:
                    if (userTrainingsChoice == 2)
                    {
                        int          liveTrainingItem = uiSrvc.TrainingMenuItems(liveTrainings.GetAllTrainings());
                        LiveTraining liveTraining     = liveTrainings.GetAllTrainings()[liveTrainingItem - 1];
                        Console.WriteLine(liveTraining.Title);
                        Console.WriteLine($"The training starts at: {liveTraining.NextSession}");
                        Console.WriteLine($"Rating: {liveTraining.Rating}");
                        Console.WriteLine($"Time: {liveTraining.Time} minutes.");
                        Console.ReadLine();
                    }
                    break;

                case "Upgrade to premium":
                    uiSrvc.UpgradeToPremium();
                    break;

                case "Reschedule training":
                    List <LiveTraining> trainings = liveTrainings.GetAllTrainings().Where(x => x.Trainer.Id == currentUser.Id).ToList();

                    if (trainings.Count == 0)
                    {
                        Console.WriteLine("No trainings!");
                        Console.ReadLine();
                    }
                    else
                    {
                        int userLiveTrainingChoice = uiSrvc.ChooseEntitiesMenu(trainings);
                        Console.WriteLine("How many days wpuld you like to reschedule the training?");
                        int days = ValidationHelper.ValidateNumber(Console.ReadLine(), 100);
                        trainerUserSrvc.GetUserById(currentUser.Id).ChangeSchedule(trainings[userLiveTrainingChoice], days);
                        Console.WriteLine("Schedule changed!");
                        Console.ReadLine();
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Seed();

            while (true)
            {
                if (_currentUser == null)
                {
                    int loginChoice = _uiService.LogInMenu();
                    if (loginChoice == 1)
                    {
                        int      roleChoice = _uiService.RoleMenu();
                        UserRole role       = (UserRole)roleChoice;
                        Console.Clear();
                        Console.WriteLine("Enter username:"******"Enter password:"******"Enter first name:");
                        newUser.FirstName = Console.ReadLine();
                        Console.WriteLine("Enter last name:");
                        newUser.LastName = Console.ReadLine();
                        Console.WriteLine("Enter username:"******"Enter password:"******"Train":
                    int trainChoice = 1;
                    if (_currentUser.Role == UserRole.Premium)
                    {
                        trainChoice = _uiService.TrainMenu();
                    }
                    if (trainChoice == 1)
                    {
                        int           trainingItem = _uiService.TrainMenuItems(_videoTrainings.GetTrainings());
                        VideoTraining training     = _videoTrainings.GetTrainings()[trainingItem - 1];
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"Link: {training.Link}");
                        Console.WriteLine($"Raiting: {training.CheckRating()}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }
                    if (trainChoice == 2)
                    {
                        int          trainingItem = _uiService.TrainMenuItems(_liveTrainings.GetTrainings());
                        LiveTraining training     = _liveTrainings.GetTrainings()[trainingItem - 1];
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"THE TRAINING STARTS AT: {training.NextSession}");
                        Console.WriteLine($"Raiting: {training.CheckRating()}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }
                    break;

                case "Upgrade to Premium":
                    _uiService.UpgradeToPremium();
                    break;

                case "Reschedule Training":
                    List <LiveTraining> trainings = _liveTrainings.GetTrainings().Where(x => x.Trainer.Id == _currentUser.Id).ToList();
                    if (trainings.Count == 0)
                    {
                        Console.WriteLine("No Trainings!");
                        Console.ReadLine();
                    }
                    else
                    {
                        int trainingChoice = _uiService.ChooseEntitiesMenu(trainings);
                        Console.WriteLine("How many days do you want to reschedule the training:");
                        int days = ValidationHelper.ValidateNumber(Console.ReadLine(), 100);
                        _trainerUserSrvc.GetById(_currentUser.Id).ChangeSchedule(trainings[trainingChoice - 1], days);
                        Console.WriteLine("Schedule changed!");
                        Console.ReadLine();
                    }
                    break;

                case "Account":
                    int accountChoice = _uiService.AccountMenu(_currentUser.Role);
                    if (accountChoice == 1)
                    {
                        //Change Info
                        Console.WriteLine("Enter new First Name:");
                        string firstName = Console.ReadLine();
                        Console.WriteLine("Enter new Last Name:");
                        string lastName = Console.ReadLine();
                        switch (_currentUser.Role)
                        {
                        case UserRole.Standard:
                            _standardUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Premium:
                            _premiumUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Trainer:
                            _trainerUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;
                        }
                    }
                    else if (accountChoice == 2)
                    {
                        //CheckSubscription
                        Console.WriteLine($"Your subscription is : {_currentUser.Role}");
                        Console.ReadLine();
                    }
                    else if (accountChoice == 3)
                    {
                        // Change Password
                        Console.WriteLine("Enter old password:"******"Enter new password:"******"Log Out":
                    _currentUser = null;
                    break;

                default:
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            Seed();
            while (true)
            {
                Console.Clear();
                int loginChoice = _uiService.LogInMenu();
                Console.Clear();
                if (loginChoice == 1)
                {
                    int      roleChoice = _uiService.RoleMenu();
                    UserRole role       = (UserRole)roleChoice;
                    Console.Clear();
                    Console.WriteLine("Enter username:"******"Enter password:"******"Enter first name:");
                    newUser.FirstName = Console.ReadLine();
                    Console.WriteLine("Enter last name:");
                    newUser.LastName = Console.ReadLine();
                    Console.WriteLine("Enter username:"******"Enter password:"******"Link: {training.Link}");
                    Console.WriteLine($"Rating: {training.CheckRating()}");
                    Console.WriteLine($"Time: {training.Time} minutes");
                    Console.ReadLine();
                }
                if (trainChoice == 2)
                {
                    int          trainingItem = _uiService.TrainMenuItems(_liveTrainings.GetTrainings());
                    LiveTraining training     = _liveTrainings.GetTrainings()[trainingItem - 1];
                    Console.WriteLine(training.Title);
                    Console.WriteLine($"THE TRAINING STARTS AT: {training.NextSession}");
                    Console.WriteLine($"Rating: {training}");
                    Console.WriteLine($"Time: {training} minutes");
                }
                break;

            case MenuItemsConstants.UpgradeToPremium:
                _uiService.UpgradeToPremium();
                break;

            case MenuItemsConstants.RescheduelTraining:
                var trainings = _liveTrainings
                                .GetTrainings()
                                .Where(x => x.Trainer.Id == _currentUser.Id)
                                .ToList();
                if (trainings.Count == 0)
                {
                    Console.WriteLine("No Trainings!");
                    Console.ReadLine();
                }
                else
                {
                    int trainingChoice = _uiService.ChooseEntiiesMenu(trainings);
                    Console.WriteLine("How many days do you want to reschedule the training: ");
                    int days = ValidationHelper.ValidateNumber(Console.ReadLine(), 100);
                    _trainerUserSrvc.GetById(_currentUser.Id)
                    .ChangeSchedule(trainings[trainingChoice - 1], days);
                    Console.WriteLine("Schedule changed!");
                    Console.ReadLine();
                }
                break;

            case MenuItemsConstants.Account:
                break;

            case MenuItemsConstants.LogOut:
                _currentUser = null;
                break;

            default:
                break;
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            // Calling the seed method in order to fill in the database with inital data if it is empty
            Seed();
            while (true)
            {
                // If it is null, it means that nobody is logged in
                // We can generate the menu for log in
                if (_currentUser == null)
                {
                    // Menu for log in or register
                    // Program -> Log in Menu method -> Generate a new menu method -> Validate a number
                    // Validate a number -> Generate a new menu mehod -> Log in Menu method -> Program
                    int loginChoice = _uiSrvc.LogInMenu();
                    // This if checks if the number the user entered is 1. If it is give them log in menu
                    if (loginChoice == 1)
                    {
                        // Menu for the user role if they want to log in
                        int roleChoice = _uiSrvc.RoleMenu();
                        // We map the user choice of 1 2 or 3 to the enum so we can have it as an enum
                        UserRole role = (UserRole)roleChoice;
                        // UserRole brokenRole = UserRole.1; // This will not work
                        // UserRole standard = (UserRole)1; // This will work and will get the Standard enum since it is number 1 in the enum
                        Console.Clear();
                        // Give the log in menu if they want to log in
                        Console.WriteLine("Enter username:"******"Enter password:"******"Enter first name:");
                        newUser.FirstName = Console.ReadLine();
                        Console.WriteLine("Enter last name:");
                        newUser.LastName = Console.ReadLine();
                        Console.WriteLine("Enter username:"******"Enter password:"******"Train":
                    // We have 2 kinds of training: Video and Live
                    // But standard users only have access to Video and not Live, while Premium have access to both
                    // Because this is the case we set the default choice to 1, which corelates to Video Trainings
                    // IF the user is premium we give them a choice to pick Live or Video and then change the choice accordingly
                    int trainChoice = 1;
                    if (_currentUser.Role == UserRole.Premium)
                    {
                        trainChoice = _uiSrvc.TrainMenu();
                    }
                    // Video trainings
                    if (trainChoice == 1)
                    {
                        int           trainingItem = _uiSrvc.TrainMenuItems(_videoTrainings.GetTrainings());
                        VideoTraining training     = _videoTrainings.GetTrainings()[trainingItem - 1];
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"Link: {training.Link}");
                        Console.WriteLine($"Raiting: {training.CheckRating()}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }
                    // Live trainings
                    if (trainChoice == 2)
                    {
                        int          trainingItem = _uiSrvc.TrainMenuItems(_liveTrainings.GetTrainings());
                        LiveTraining training     = _liveTrainings.GetTrainings()[trainingItem - 1];
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"THE TRAINING STARTS AT: {training.NextSession}");
                        Console.WriteLine($"Raiting: {training.CheckRating()}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }
                    break;

                case "Upgrade to Premium":
                    _uiSrvc.UpgradeToPremium();
                    break;

                case "Reschedule training":
                    List <LiveTraining> trainings = _liveTrainings.GetTrainings().Where(x => x.Trainer.Id == _currentUser.Id).ToList();
                    if (trainings.Count == 0)
                    {
                        Console.WriteLine("No Trainings!");
                        Console.ReadLine();
                    }
                    else
                    {
                        int trainingChoice = _uiSrvc.ChooseEntiiesMenu(trainings);
                        Console.WriteLine("How many days do you want to reschedule the training:");
                        int days = ValidationHelper.ValidateNumber(Console.ReadLine(), 100);
                        _trainerUserSrvc.GetUserById(_currentUser.Id).ChangeSchedule(trainings[trainingChoice - 1], days);
                        Console.WriteLine("Schedule changed!");
                        Console.ReadLine();
                    }
                    break;

                case "Account":
                    int accountChoice = _uiSrvc.AccountMenu(_currentUser.Role);
                    Console.Clear();
                    if (accountChoice == 1)
                    {
                        // Change Info
                        Console.WriteLine("Enter new First Name:");
                        string firstName = Console.ReadLine();
                        Console.WriteLine("Enter new Last Name:");
                        string lastName = Console.ReadLine();
                        switch (_currentUser.Role)
                        {
                        case UserRole.Standard:
                            _standardUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Premium:
                            _premiumUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Trainer:
                            _trainerUserSrvc.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;
                        }
                    }
                    else if (accountChoice == 2)
                    {
                        // Check Subscription
                        Console.WriteLine($"Your subscription is: {_currentUser.Role}");
                        Console.ReadLine();
                    }
                    else if (accountChoice == 3)
                    {
                        // Change info
                        Console.WriteLine("Enter old password:"******"Enter new password:"******"Log Out":
                    _currentUser = null;
                    break;

                default:
                    break;
                }
            }
        }