Esempio n. 1
0
        private static Menu NewSearchMenu(IContactsStorage storage)
        {
            var searchMenu = new Menu("Search by:");

            foreach (var fieldKind in (Contact.FieldKind[]) typeof(Contact.FieldKind).GetEnumValues())
            {
                searchMenu.AddItem(new MenuItem(Contact.GetFieldKindName(fieldKind), () => {
                    SearchByField(fieldKind, storage);
                }));
            }

            searchMenu.AddItem(new MenuItem("Back", () => { return; }));

            return(searchMenu);
        }
Esempio n. 2
0
        public override IReadOnlyCollection <Contact> FindByField(Contact.FieldKind fieldKind, string query)
        {
            Console.WriteLine($"Searching contacts by {Contact.GetFieldKindName(fieldKind)} at {BaseUri}");
            if (!DoHttpReqeust(httpClient.GetAsync(new Uri(BaseUri, $"/api/findBy?field={fieldKind}&query={query}")), out string response))
            {
                Console.WriteLine(response);
                return(new ReadOnlyCollection <Contact>(new List <Contact> {
                }));
            }

            List <Contact> parsed = Contact.ParseMany(response, out int parsedCounter, out int totalCounter);

            Console.WriteLine(IO.ComposeSummaryString("parsed", parsedCounter, totalCounter));

            return(new ReadOnlyCollection <Contact>(parsed));
        }
Esempio n. 3
0
        private static void SearchByField(Contact.FieldKind fieldKind, IContactsStorage storage)
        {
            string query;

            if (fieldKind != Contact.FieldKind.Birthday)
            {
                query = IO.ReadString(Contact.GetFieldKindName(fieldKind) + " substring: ");
            }
            else
            {
                query = IO.ReadBirthday();
            }

            IO.PrintContactList(
                searchResultsHeader,
                storage.FindByField(fieldKind, query)
                );
        }