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); } }
private static void Find(string parameters) { string[] findParametrs = parameters.Split(' ', 2); string temp; DateTime dateTime; if (findParametrs.Length != 2) { Console.WriteLine("Write command with Find, try again."); return; } string paramOfFind = findParametrs[0]; if (paramOfFind.ToUpper(regionalSetting) == "FIRSTNAME") { temp = findParametrs[1].Trim('"').ToUpper(regionalSetting); PrintRecords(fileCabinetService.FindByFirstName(temp)); } else if (paramOfFind.ToUpper(regionalSetting) == "LASTNAME") { temp = findParametrs[1].Trim('"').ToUpper(regionalSetting); PrintRecords(fileCabinetService.FindByLastName(temp)); } else if (paramOfFind.ToUpper(regionalSetting) == "DATEOFBIRTH") { temp = findParametrs[1].Trim('"'); if (DateTime.TryParse(temp, out dateTime)) { PrintRecords(fileCabinetService.FindByDateOfBirthName(dateTime)); } else { Console.WriteLine("Command is not correct, try again."); return; } } else { Console.WriteLine("Command is not correct, try again."); return; } }
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."); } }