public T LogIn(string username, string password)
        {
            var users = _dB.GetAll();
            T   user  = null;

            if (!ValidationHelpers.DoesUserNameExists(users, username))
            {
                for (int i = 1; i <= 3; i++)
                {
                    MessageHelpers.Message("You have been entered userName that not exixst", ConsoleColor.Red);
                    Console.WriteLine("Enter your username again: ");
                    username = Console.ReadLine();
                    if (ValidationHelpers.DoesUserNameExists(users, username))
                    {
                        break;
                    }
                    if (i == 3 && !ValidationHelpers.DoesUserNameExists(users, username))
                    {
                        Environment.Exit(0);
                    }
                }
            }
            Console.Clear();
            user = users.FirstOrDefault(user => user.Username == username);

            if (!ValidationHelpers.ThreeChanceForLogin(user, password))
            {
                Environment.Exit(0);
            }
            Console.Clear();
            MessageHelpers.Message("You succesfully logged in!", ConsoleColor.Green);
            return(user);
        }
        public void ChangePassword(int userId, string oldPassword, string newPassword)
        {
            var user = _dB.GetUserById(userId);

            if (ValidationHelpers.ValidatePassword(newPassword) == null)
            {
                MessageHelpers.Message("The password you entered must contain at least one capital letter, at least one number " +
                                       "and should not be shorter than 6 characters", ConsoleColor.Red);
                return;
            }
            user.Password = newPassword;
            _dB.UpdateUser(user);
            MessageHelpers.Message("You succesfully changed your password", ConsoleColor.Green);
        }
        public void ChangeInfo(int userId, string firstName, string lastName)
        {
            var user = _dB.GetUserById(userId);

            if (!ValidationHelpers.ValidateFirstNameAndLastName(firstName, lastName))
            {
                MessageHelpers.Message("The first and last name should not be shorter than 2 characters and must not contain numbers!", ConsoleColor.Red);
                return;
            }
            user.FirstName = firstName;
            user.LastName  = lastName;
            _dB.UpdateUser(user);
            MessageHelpers.Message("You succesfully changed your info", ConsoleColor.Green);
        }
        public T Register(T user)
        {
            if (!ValidationHelpers.ValidateFirstNameAndLastName(user.FirstName, user.LastName) ||
                ValidationHelpers.AgeValidation(user.Age) == -1 ||
                ValidationHelpers.ValidateUserName(user.Username) == null ||
                ValidationHelpers.ValidatePassword(user.Password) == null)
            {
                MessageHelpers.Message("You have entered something wrong!", ConsoleColor.Red);
                Console.ReadLine();
                return(null);
            }
            int id = _dB.Insert(user);

            return(_dB.GetUserById(id));
        }
        public void TrackingTime(ActivityType activity, User user)
        {
            Console.Clear();
            switch (activity)
            {
            case ActivityType.Reading:
                var reading = new Reading();
                reading.TrackTime();
                Console.WriteLine("Please enter how many pages you've read and what kind Of book you were reading:");
                Console.Write("Pages: ");
                reading.Pages       = ValidationHelpers.TryParseNumber(Console.ReadLine(), int.MaxValue);
                reading.ReadingType = (ReadingType)menus.ShowBookTypes();
                MessageHelpers.Message("Activity is succesfully tracked!", ConsoleColor.Green);
                user.ListOfActivities.Add(reading);
                break;

            case ActivityType.Exercising:
                var exercising = new Exercising();
                exercising.TrackTime();
                Console.WriteLine("Please enter what kind of workout did you do");
                exercising.ExercisingType = (ExercisingType)menus.ShowExercise();
                MessageHelpers.Message("Activity is succesfully tracked!", ConsoleColor.Green);
                user.ListOfActivities.Add(exercising);
                break;

            case ActivityType.Working:
                var working = new Working();
                working.TrackTime();
                Console.WriteLine("Where were you working from?");
                working.WorkingType = (WorkingType)menus.ShowWorkingPlace();
                MessageHelpers.Message("Activity is succesfully tracked!", ConsoleColor.Green);
                user.ListOfActivities.Add(working);
                break;

            case ActivityType.OtherHobbies:
                var otherHobbies = new OtherHobbies();
                otherHobbies.TrackTime();
                Console.WriteLine("Please enter the name of the hobby");
                otherHobbies.HobbyName = Console.ReadLine();
                MessageHelpers.Message("Activity is succesfully tracked!", ConsoleColor.Green);
                user.ListOfActivities.Add(otherHobbies);
                break;

            default:
                break;
            }
        }
Beispiel #6
0
        public int ChooseOnMenu <T>(List <T> list)
        {
            Console.WriteLine("Enter a number to choose");
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine($"{i + 1}.) {list[i]} ");
            }

            int choice = ValidationHelpers.TryParseNumber(Console.ReadLine(), list.Count);

            if (choice == -1)
            {
                MessageHelpers.Message("You've entered something wrong! Try again!", ConsoleColor.Red);
                Thread.Sleep(2000);
            }
            return(choice);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            UsersList();
            //_menu.HomeScreen();

            while (true)
            {
                int menuChoice = _menu.LogInMenu();
                switch (menuChoice)
                {
                case 1:
                    Console.WriteLine("Enter username: "******"Enter password: "******"Enter your First Name: ");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Enter your Last Name: ");
                    string lastName = Console.ReadLine();
                    Console.WriteLine("Enter your userName: "******"Enter your password: "******"Enter your age: ");
                    int age = ValidationHelpers.TryParseNumber(Console.ReadLine(), 120);

                    var user = new User(firstName, lastName, nameUser, userPassword, age);

                    _currentUser = _userService.Register(user);
                    if (_currentUser == null)
                    {
                        MessageHelpers.Message("Unsuccesful registration please try again", ConsoleColor.Red);
                        Thread.Sleep(1500);
                        continue;
                    }
                    MessageHelpers.Message("You succesfully registered!", ConsoleColor.Green);
                    break;

                case 3:
                    Environment.Exit(0);
                    break;
                }

                bool isLoggedIn = true;
                while (isLoggedIn)
                {
                    Console.WriteLine($"Hi {_currentUser.FirstName} choose one of the following?");
                    int          choice          = _menu.MainMenu();
                    ActivityType currentActivity = (ActivityType)choice;
                    Console.Clear();
                    switch (choice)
                    {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                        _activityServices.TrackingTime(currentActivity, _currentUser);
                        break;

                    case 5:
                        if (!ValidationHelpers.CheckIfListIsEmpty(_currentUser.ListOfActivities, "statistics"))
                        {
                            continue;
                        }
                        int statisticsMenu = _menu.StatisticsMenu();
                        _userService.UserStatistics(_currentUser, statisticsMenu);
                        break;

                    case 6:
                        int accountMenu = _menu.AccountMenu();
                        if (_userService.AccountSettings(_currentUser.Id, accountMenu, _currentUser))
                        {
                            isLoggedIn = !isLoggedIn;
                        }
                        break;

                    case 7:
                        isLoggedIn = !isLoggedIn;
                        break;

                    default:
                        break;
                    }
                }
            }
        }