private void AddExistingAward(int user_id) { int records_on_page = 10; IAward[] awards = logic.GetAllAwards(); int max_page = awards.Length / records_on_page; if (awards.Length % records_on_page != 0) { max_page++; } int current_page = 1; while (true) { Console.Clear(); Console.WriteLine($"DataBase contains {awards.Length} awards."); Console.WriteLine($"Page {current_page}/{max_page}"); int last_index_of_page = current_page * records_on_page; if (last_index_of_page > awards.Length) { last_index_of_page = awards.Length; } int records_counter = 0; for (int i = (current_page - 1) * records_on_page; i >= 0 && i < last_index_of_page; i++, records_counter++) { Console.WriteLine($"{records_counter}) {awards[i].Title}"); } Console.WriteLine("Choise your action:"); Console.WriteLine("0-9) Add award"); if (current_page < max_page) { Console.WriteLine("n) Next page"); } if (current_page > 1) { Console.WriteLine("p) Prev page"); } Console.WriteLine("e) Back"); Console.Write("> "); char input = '\0'; while (true) { while (!char.TryParse(Console.ReadLine(), out input)) { Console.WriteLine("Input error!"); Console.WriteLine("Enter character."); Console.Write("> "); continue; } if ((input < '0' || input > '9') && input != 'n' && input != 'p' && input != 'e') { Console.WriteLine("Input error!"); Console.WriteLine("Enter 0-9, n, p or e."); Console.Write("> "); continue; } if (input >= '0' && input <= '9') { if (awards.Length == 0) { Console.WriteLine("Input error!"); Console.WriteLine($"DataBase have not awards."); Console.Write("> "); continue; } else { if (input >= records_counter + '0') { Console.WriteLine("Input error!"); Console.WriteLine($"Last record is {records_counter}."); Console.Write("> "); continue; } } } if (input == 'n' && current_page >= max_page) { Console.WriteLine("Input error!"); Console.WriteLine($"Have not next page"); Console.Write("> "); continue; } if (input == 'p' && current_page <= 1) { Console.WriteLine("Input error!"); Console.WriteLine($"Have not prev page"); Console.Write("> "); continue; } break; } if (input >= '0' && input <= '9') { int index = (input - '0') + (current_page - 1) * records_on_page; logic.AddAwardToUser(user_id, index); break; } switch (input) { case 'n': current_page++; break; case 'p': current_page--; break; case 'e': return; } } }