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;
                }
            }
        }