Пример #1
0
        private static void add_elements <T>(LstCollection <T> l) where T : BaseClass, new()
        {
            var p = new T();

            p.Input();
            l.AddItem(p);
        }
Пример #2
0
        private static void search_elements <T>(LstCollection <T> l) where T : BaseClass, new()
        {
            Console.WriteLine("Enter parameter which elements you want to find: \n");
            var res = new LstCollection <T>(l.Search(Console.ReadLine()));

            Console.WriteLine(res);
        }
Пример #3
0
 private static void sort_elements <T>(LstCollection <T> l) where T : BaseClass, new()
 {
     Console.WriteLine("Enter field for which you want to sort: \n" +
                       "POSSIBLE: Title, Image_url, Price, Created_at, " +
                       "Updated_at, Description, Id:\n");
     l.Sort(Console.ReadLine());
 }
Пример #4
0
        public static void Main(string[] args)
        {
            LstCollection <Product> l = new LstCollection <Product>();

            while (true)
            {
                Console.WriteLine(get_help_message());
                string task = Console.ReadLine();
                switch (task)
                {
                case "1":
                    Validation.ValidateInput(l, read_txt_file);
                    break;

                case "2":
                    Validation.ValidateInput(l, sort_elements);
                    break;

                case "3":
                    Validation.ValidateInput(l, search_elements);
                    break;

                case "4":
                    Validation.ValidateInput(l, add_elements);
                    break;

                case "5":
                    Validation.ValidateInput(l, del_element);
                    break;

                case "6":
                    Validation.ValidateInput(l, edit_element);
                    break;

                case "7":
                    Validation.ValidateInput(l, write_file);
                    break;

                case "8":
                    Validation.ValidateInput(l, add_txt_file);
                    break;

                case "9":
                    Console.WriteLine(l);
                    break;

                case "exit":
                    Console.WriteLine("GOODBYE!");
                    return;

                default:
                    Console.WriteLine("WRONG INPUT!");
                    continue;
                }
                Console.WriteLine();
            }
        }
Пример #5
0
        private static void edit_element <T>(LstCollection <T> l) where T : BaseClass, new()
        {
            Console.Write("Enter id to edit: ");
            var id = Console.ReadLine();

            Console.Write("Enter atter to edit: ");
            var atter = Console.ReadLine();

            Console.Write("Enter value to change: ");
            var value = Console.ReadLine();

            l.Edit(id, atter, value);
        }
Пример #6
0
        private static void read_txt_file <T>(LstCollection <T> l) where T : BaseClass, new()
        {
            Console.WriteLine("Enter file_name: ");
            var file = Validation.ValidateFile(Console.ReadLine());

            if (file.EndsWith(".txt"))
            {
                l.ReadTxtFile(file);
            }
            else
            {
                l.ReadJsonFile(file);
            }
        }
Пример #7
0
 public static void ValidateInput <T>(LstCollection <T> l, MyFunction <T> f) where T : BaseClass, new()
 {
     while (true)
     {
         try
         {
             f(l);
             break;
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             Console.WriteLine("Try one more time!");
             continue;
         }
     }
 }
Пример #8
0
 private static void add_txt_file <T>(LstCollection <T> l) where T : BaseClass, new()
 {
     Console.WriteLine("Enter file_name: ");
     l.AddToTxtFile(Validation.ValidateFile(Console.ReadLine()));
 }
Пример #9
0
 private static void del_element <T>(LstCollection <T> l) where T : BaseClass, new()
 {
     Console.WriteLine("Enter id to delete: ");
     l.Delete(Console.ReadLine());
 }