private static void add_elements(LstCollection l) { var p = new Product(); p.InputProduct(); l.AddItem(p); }
private static void search_elements(LstCollection l) { Console.WriteLine("Enter parameter which elements you want to find: \n"); var res = new LstCollection(l.Search(Console.ReadLine())); Console.WriteLine(res); }
private static void sort_elements(LstCollection l) { 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()); }
public static void Main(string[] args) { LstCollection l = new LstCollection(); 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_product); break; case "6": Validation.ValidateInput(l, edit_product); 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(); } }
private static void edit_product(LstCollection l) { 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); }
private static void write_file(LstCollection l) { Console.WriteLine("Enter file_name: "); var file = Validation.ValidateFile(Console.ReadLine()); if (file.EndsWith(".txt")) { l.WriteTxtFile(file); } else { l.WriteJsonFile(file); } }
public static void ValidateInput(LstCollection l, MyFunction f) { while (true) { try { f(l); break; } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Try one more time!"); continue; } } }
private static void add_txt_file(LstCollection l) { Console.WriteLine("Enter file_name: "); l.AddToTxtFile(Validation.ValidateFile(Console.ReadLine())); }
private static void del_product(LstCollection l) { Console.WriteLine("Enter id to delete: "); l.Delete(Console.ReadLine()); }