string StartRulesView(TamagotchiContract tama) { var rules = tama.Rules; var index = 0; Func <RuleContract> current = () => rules.ElementAt(index); Action next = () => index = (index + 1) % rules.Count(); Action refresh = () => { tama = _repo.Get(tama.ID); rules = tama.Rules; }; while (true) { var rule = current.Invoke(); System.Console.Clear(); WriteHeader(); WriteTamagotchiStatus(tama); WriteLine("Type [quit] to close the application."); WriteLine("Type [back] to go back to the start."); WriteLine("Type [next] to go to the next rule"); if (rule.IsActive) { WriteLine("Type [off] to deactivate the rule"); } else { WriteLine("Type [on] to activate the rule"); } WriteLine(); Write($"[Name: {rule.Name}] [Active: ", ConsoleColor.Gray); ConsoleColor color = ConsoleColor.Green; if (!rule.IsActive) { color = ConsoleColor.Red; } Write($"{rule.IsActive}", color); Write("]", ConsoleColor.Gray); WriteLine(); WriteLine($"Discription:{NewLine}[{rule.Discription}]"); WriteLine(); try { _repo.HasData(); } catch (Exception) { ShowConnectionError(); } var input = AskForInput(); if (input == "off") { _repo.SetRule(tama.Name, rule.Name, false); refresh.Invoke(); continue; } if (input == "on") { _repo.SetRule(tama.Name, rule.Name, true); refresh.Invoke(); continue; } if (input == "next") { next.Invoke(); continue; } if (input == "quit" || input == "back") { return(input); } } }