Esempio n. 1
0
        public void MenuStart(RegistrationPerson person, List <Poll> polList)
        {
            Console.WriteLine($"Welcome {person.FirstName}");
            Console.WriteLine($"Choose what you want to do ");

            while (true)
            {
                var accountWork = new AccountPollWork();
                Console.WriteLine("1: Vote ");
                Console.WriteLine("2: Logout");
                while (!int.TryParse(Console.ReadLine(), out _chooseMenu) && _chooseMenu <= 0 || _chooseMenu > 2)
                {
                    Console.WriteLine("Error input , chose something from 1 to 2");
                    break;
                }

                switch (_chooseMenu)
                {
                case 1:
                    accountWork.MakePoll(polList, person);
                    break;

                case 2:
                    return;
                }
            }
        }
Esempio n. 2
0
        public void WriteAnswerStat(Poll poll, RegistrationPerson person, string[] answers)
        {
            var answersPuck = new ReadyAnswers
            {
                VariantAnswer = answers,
                Age           = person.Age,
                IsMan         = person.IsGenderMan
            };

            poll.Stat.Answers.Add(answersPuck);
        }
Esempio n. 3
0
        public void StartMenu(List <RegistrationPerson> persons, List <Poll> pollList)
        {
            Console.WriteLine();
            while (_firstWork)
            {
                RegistrationPerson account = new RegistrationPerson();
                Console.WriteLine("1: Registration");
                Console.WriteLine("2: Login");
                Console.WriteLine("3: Exit");
                while (!int.TryParse(Console.ReadLine(), out _chooseMenu) && _chooseMenu <= 0 || _chooseMenu > 3)
                {
                    Console.WriteLine("Error input , chose something from 1 to 3");
                    break;
                }
                switch (_chooseMenu)
                {
                case 1:
                    persons.Add(account.Registration(pollList, persons));
                    if (persons.Last() == null)
                    {
                        persons.Remove(persons.Last());
                        continue;
                    }
                    else
                    {
                        account = persons.Last();
                    }
                    account.Update(persons);
                    _personAccount = account;
                    _firstWork     = false;
                    break;

                case 2:
                    account = account.LoginIn(persons);
                    if (account == null)
                    {
                        Console.WriteLine("Incorrect login or password");
                    }
                    else
                    {
                        _personAccount = account;
                        _firstWork     = false;
                    }
                    break;

                case 3:
                    return;

                default:
                    continue;
                }
            }
        }
Esempio n. 4
0
        public void WriteStat(Poll poll, RegistrationPerson person)
        {
            poll.Stat.Votes++;
            switch (person.IsGenderMan)
            {
            case false:
                if (person.Age < 18)
                {
                    poll.Stat.WomanTo18++;
                }
                else if (person.Age >= 18 && person.Age <= 30)
                {
                    poll.Stat.WomanFrom18To30++;
                }
                else
                {
                    poll.Stat.WomanFrom30++;
                }
                break;

            case true:
                if (person.Age < 18)
                {
                    poll.Stat.ManTo18++;
                }
                else if (person.Age >= 18 && person.Age <= 30)
                {
                    poll.Stat.ManFrom18To30++;
                }
                else
                {
                    poll.Stat.ManFrom30++;
                }
                break;
            }
        }
Esempio n. 5
0
        public RegistrationPerson Registration(List <Poll> pollList, List <RegistrationPerson> listPeople)
        {
            Console.Write("What is your name ?   ");
            var name = Console.ReadLine();

            if (string.IsNullOrEmpty(name.Trim()))
            {
                Console.WriteLine("Cant be empty");
                return(null);
            }

            Console.Write("What is your last name ?  ");
            var lastName = Console.ReadLine();

            if (string.IsNullOrEmpty(lastName.Trim()))
            {
                Console.WriteLine("Cant be empty");
                return(null);
            }
            Console.Write("What is your age ?  ");

            if (!int.TryParse(Console.ReadLine(), out var age) || age > 120 || age <= 0)
            {
                Console.WriteLine("Incorrect input , age must be correct ");
                return(null);
            }
            if (age <= 5)
            {
                Console.WriteLine("Sorry but you are too young");
                return(null);
            }
            Console.Write("Your gender ? (Male(M)/Female(F)) ");
            var  gender = Console.ReadKey();
            bool isMan;

            switch (gender.Key)
            {
            case ConsoleKey.M:
                isMan = true;
                break;

            case ConsoleKey.F:
                isMan = false;
                break;

            default:
                Console.WriteLine("Sorry but you must have standard gender ");
                return(null);
            }
            Console.WriteLine();

            Console.Write("Your phone number ? (Without country code (must have 9 symbols ))  ");
            if (!int.TryParse(Console.ReadLine(), out var phone) || phone.ToString().Length != 9)
            {
                Console.WriteLine("incorrect phone number ");
                return(null);
            }

            try
            {
                var registered = listPeople.Select(x => x).Where(x => x.Phone == phone);
                if (registered.Any())
                {
                    Console.WriteLine("This account is already registered");
                    return(null);
                }
            }
            catch
            {
                Console.WriteLine("Some Add another account with the same login directly in file ");
                return(null);
            }


            Console.Write("Create a password ");
            var password = Console.ReadLine();

            if (string.IsNullOrEmpty(password.Trim()))
            {
                Console.WriteLine("Cant be empty");
                return(null);
            }

            RegistrationPerson registeredPerson = new RegistrationPerson()
            {
                FirstName   = name.Trim(),
                LastName    = lastName.Trim(),
                Age         = age,
                IsGenderMan = isMan,
                Phone       = phone,
                Password    = password.Trim()
            };

            return(registeredPerson);
        }
Esempio n. 6
0
        public void MakePoll(List <Poll> polList, RegistrationPerson person)
        {
            Console.WriteLine("Select a poll what you want to start  ");
            var sortedPolList = polList.Select(x => x).OrderBy(x => x.Id).ToList();

            sortedPolList.ForEach(x => Console.WriteLine($"{x.Id} poll :  { x.PollName }"));


            if (!int.TryParse(Console.ReadLine(), out var idPoll))
            {
                Console.WriteLine("Incorrect input , age must be correct ");
                return;
            }


            Poll selectedPoll;

            try
            {
                selectedPoll = polList.Select(x => x).Single(x => x.Id == idPoll);
            }
            catch
            {
                Console.WriteLine("Error input , you must choose id ");
                return;
            }

            if (selectedPoll.PassedLogins.Contains(person.Phone))
            {
                Console.WriteLine("You have been voted in this poll , choose another one ");
                return;
            }



            var answers = new string[selectedPoll.Questions.Length];


            for (var i = 0; i <= selectedPoll.Questions.Length - 1; i++)
            {
                var index          = 1;
                var variantAnswers = new VariantAnswers();
                Console.WriteLine(selectedPoll.Questions[i]);
                try
                {
                    variantAnswers = selectedPoll.VariantAnswers.Select(x => x).Single(x => x.IndexQuestion == i);
                    foreach (var answer in variantAnswers.VariantAnswer)
                    {
                        Console.WriteLine($"{index} : {answer}");
                        index++;
                    }
                }
                catch
                {
                }

                if (variantAnswers.VariantAnswer == null)
                {
                    answers[i] = Console.ReadLine();
                }
                else
                {
                    while (true)
                    {
                        if (!int.TryParse(Console.ReadLine(), out var answerNum))
                        {
                            Console.WriteLine("Incorrect input , if you want and this poll , without save press 0 ");
                            continue;
                        }
                        if (answerNum == 0)
                        {
                            return;
                        }
                        try
                        {
                            answers[i] = variantAnswers.VariantAnswer[answerNum - 1];
                            break;
                        }
                        catch
                        {
                            Console.WriteLine("Incorrect this id of answer, if you want and this poll , without save press 0 ");
                        }
                    }
                }
            }

            selectedPoll.PassedLogins.Add(person.Phone);
            WriteStat(selectedPoll, person);
            WriteAnswerStat(selectedPoll, person, answers);
            var newPoll = selectedPoll;

            polList.Remove(selectedPoll);
            polList.Add(newPoll);
            Update.UpdateFile(polList);
        }