コード例 #1
0
        public string BuildNewSpecialDestinationString(string msg, bool isNeedConfirmation = false)
        {
            string output;

            while (true)
            {
                bool passwordNotConfirmed = true;
                if (destination == StringDestination.PassportType || destination == StringDestination.Email)
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor($"What is your {msg}?", ConsoleColor.Yellow);
                }
                else
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor($"Try to come up with  {msg}?", ConsoleColor.Yellow);
                }
                Console.Write($"{msg}--> ");
                output = Console.ReadLine()
                         ?.Trim()
                         .Replace(" ", "");
                if (String.IsNullOrEmpty(output))
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor("Wrong data!", ConsoleColor.Red);
                    continue;
                }
                if (destination == StringDestination.Password && output.Length < 6)
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor("Wrong password length!", ConsoleColor.Red);
                    continue;
                }
                if (destination == StringDestination.Email && !StringValidator.IsEmailValid(output))
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor("This email is not valid!", ConsoleColor.Red);
                    continue;
                }
                if (destination == StringDestination.Password)
                {
                    if (isNeedConfirmation == true)
                    {
                        break;
                    }
                    ColorTextWriterService.PrintLineMessageWithSpecialColor("You need to confirm password!", ConsoleColor.Yellow);
                    string confirmationPassword;
                    do
                    {
                        Console.Write("Confirmation--> ");
                        confirmationPassword = Console.ReadLine()
                                               ?.Trim()
                                               .Replace(" ", "");
                        if (String.IsNullOrEmpty(output))
                        {
                            ColorTextWriterService.PrintLineMessageWithSpecialColor("Wrong data!", ConsoleColor.Red);
                            continue;
                        }
                        if (output == confirmationPassword)
                        {
                            ColorTextWriterService.PrintLineMessageWithSpecialColor("Password confirmed", ConsoleColor.Green);
                            passwordNotConfirmed = false;
                        }
                        else
                        {
                            ColorTextWriterService.PrintLineMessageWithSpecialColor("Passwords dont match!", ConsoleColor.Red);
                        }
                    } while (passwordNotConfirmed);
                }
                if (destination == StringDestination.PassportType && StringValidator.IsStringContainsDigits(output))
                {
                    ColorTextWriterService.PrintLineMessageWithSpecialColor("You cannot enter nameType with digits!", ConsoleColor.Red);
                    continue;
                }
                break;
            }
            return(output);
        }