Пример #1
0
        private static void Find(string parameters)
        {
            var options = parameters.Split(SpaceChar);

            List <FileCabinetRecord> result = new List <FileCabinetRecord>();

            try
            {
                if (options.Length != MinCountOfOptions)
                {
                    throw new ArgumentOutOfRangeException($"{nameof(options)} can't contain not 2 parameters.");
                }

                string firstOption  = options[0];
                string secondOption = options[1];

                secondOption = secondOption.Trim(QuotationMarkChar, SingleQuoteChar).Trim();

                if (firstOption.Equals(FindFirstNameString, StringComparison.InvariantCultureIgnoreCase))
                {
                    result = fileCabinetService.FindByFirstName(secondOption);
                }
                else if (firstOption.Equals(FindLastNameString, StringComparison.InvariantCultureIgnoreCase))
                {
                    result = fileCabinetService.FindByLastName(secondOption);
                }
                else if (firstOption.Equals(FindDateOfBirthString, StringComparison.InvariantCultureIgnoreCase))
                {
                    result = fileCabinetService.FindByDateOfBirth(DateConvert(secondOption));
                }

                if (result.Count == 0)
                {
                    Console.WriteLine($"records with the {firstOption} {secondOption} was not found.");
                }
                else
                {
                    foreach (var r in result)
                    {
                        Console.WriteLine(r);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        private static void Find(string parameters)
        {
            if (!string.IsNullOrEmpty(parameters))
            {
                var index = Array.FindIndex(findProperties, 0, findProperties.Length, i => string.Equals(i[Program.CommandHelpIndex], parameters.Split(' ')[0], StringComparison.InvariantCultureIgnoreCase));

                // Refactor condition statements
                if (index == 0)
                {
                    foreach (var item in fileCabinetService.FindByFirstName(parameters.Split(' ')[1]))
                    {
                        Console.WriteLine($"#{item.Id}, {item.FirstName}, {item.LastName}, {item.DateOfBirth.ToString("yyyy-MMM-dd", cultureInfo)}, {item.Age}, {item.Money}, {item.Letter}");
                    }
                }

                if (index == 1)
                {
                    foreach (var item in fileCabinetService.FindByLastName(parameters.Split(' ')[1]))
                    {
                        Console.WriteLine($"#{item.Id}, {item.FirstName}, {item.LastName}, {item.DateOfBirth.ToString("yyyy-MMM-dd", cultureInfo)}, {item.Age}, {item.Money}, {item.Letter}");
                    }
                }

                if (index == 2)
                {
                    foreach (var item in fileCabinetService.FindByDateOfBirth(parameters.Split(' ')[1]))
                    {
                        Console.WriteLine($"#{item.Id}, {item.FirstName}, {item.LastName}, {item.DateOfBirth.ToString("yyyy-MMM-dd", cultureInfo)}, {item.Age}, {item.Money}, {item.Letter}");
                    }
                }
            }
            else
            {
                Console.WriteLine("Enter property and query.");
            }
        }