Exemplo n.º 1
0
        static void AssignChore(ChoreRepository choreRepo, RoommateRepository roommateRepo)
        {
            List <Chore>    allChores    = choreRepo.GetAll();
            List <Roommate> allRoommates = roommateRepo.GetAll();

            // Select a chore
            Console.Clear();
            Console.SetCursorPosition((Console.WindowWidth - 13) / 2, Console.CursorTop);
            Console.WriteLine("Assign Chores");
            Console.SetCursorPosition((Console.WindowWidth - 13) / 2, Console.CursorTop);
            Console.WriteLine("-------------");
            Console.WriteLine("\nPlease choose a chore to assign:");
            for (int i = 1; i < allChores.Count + 1; i++)
            {
                Console.WriteLine($"{i}) {allChores[i-1].Name}");
            }
            Console.WriteLine();
            string userSelection  = Console.ReadLine();
            bool   validSelection = int.TryParse(userSelection, out int choreNum);

            while (!validSelection || choreNum < 0 || choreNum > allChores.Count)
            {
                Console.WriteLine("Invalid selection");
                userSelection  = Console.ReadLine();
                validSelection = int.TryParse(userSelection, out choreNum);
            }
            Chore assignedChore = allChores[choreNum - 1];

            // Select a roommate
            Console.Clear();
            Console.SetCursorPosition((Console.WindowWidth - 13) / 2, Console.CursorTop);
            Console.WriteLine("Assign Chores");
            Console.SetCursorPosition((Console.WindowWidth - 13) / 2, Console.CursorTop);
            Console.WriteLine("-------------");
            Console.WriteLine($"\nAssign {assignedChore.Name} to a roommate:");
            for (int i = 1; i < allRoommates.Count + 1; i++)
            {
                Console.WriteLine($"{i}) {allRoommates[i-1].Firstname} {allRoommates[i-1].Lastname}");
            }
            Console.WriteLine();
            userSelection  = Console.ReadLine();
            validSelection = int.TryParse(userSelection, out int roommateNum);
            while (!validSelection || roommateNum < 0 || roommateNum > allRoommates.Count)
            {
                Console.WriteLine("Invalid selection");
                userSelection  = Console.ReadLine();
                validSelection = int.TryParse(userSelection, out roommateNum);
            }
            Roommate assignedRoommate = allRoommates[roommateNum - 1];

            choreRepo.Assign(assignedChore, assignedRoommate);

            Console.WriteLine($"{assignedChore.Name} has been assigned to {assignedRoommate.Firstname}");
        }
Exemplo n.º 2
0
        static void AssignChore()
        {
            ChoreRepository choreRepo = new ChoreRepository(CONNECTION_STRING);

            Console.WriteLine("-------------- Assign a Chore to a Roommate -----------------------");
            ListAllRoommates();
            string choreResponse = null;

            Console.WriteLine("Enter the ID of the Roommate to Assign a Chore: ");
            choreResponse = Console.ReadLine();
            if (choreResponse != "")
            {
                int RoommateId = Int32.Parse(choreResponse);
                choreResponse = "";
                ListChores();
                Console.WriteLine("Enter the ID of the Chore to assign: ");
                choreResponse = Console.ReadLine();
                if (choreResponse != "")
                {
                    choreRepo.Assign(RoommateId, Int32.Parse(choreResponse));
                }
            }
        }