Exemple #1
0
            static void addAChore(ChoreRepository choreRepo)
            {
                Console.Write("Chore name: ");
                string choreName  = Console.ReadLine();
                Chore  choreToAdd = new Chore()
                {
                    Name = choreName
                };

                choreRepo.Insert(choreToAdd);
                Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                Console.Write("Press any key to continue");
                Console.ReadKey();
            }
Exemple #2
0
        static void AddChore(ChoreRepository choreRepo)
        {
            Console.Write("Chore name: ");
            string name = Console.ReadLine();

            Chore choreToAdd = new Chore()
            {
                Name = name
            };

            choreRepo.Insert(choreToAdd);
            Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
            ContinueMenu();
        }
Exemple #3
0
        static void AddChore(ChoreRepository choreRepo)
        {
            Console.Write("Chore name: ");
            string name = Console.ReadLine();

            Console.Write("Max occupancy: ");
            int max = int.Parse(Console.ReadLine());

            Chore choreToAdd = new Chore()
            {
                Name = name,
            };

            choreRepo.Insert(choreToAdd);

            Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
            Console.Write("Press any key to continue");
            Console.ReadKey();
        }
Exemple #4
0
        static void AddChore()
        {
            ChoreRepository choreRepo     = new ChoreRepository(CONNECTION_STRING);
            string          choreResponse = null;

            Console.WriteLine("Here is the current list of chores...");
            ListChores();
            Console.WriteLine("Enter a chore name or press ENTER to return to the menu: ");
            choreResponse = Console.ReadLine();
            if (choreResponse != "")
            {
                Chore chore = new Chore
                {
                    Name = choreResponse
                };
                choreRepo.Insert(chore);
            }
            ListChores();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Name} has an Id of {r.Id} and a max occupancy of {r.MaxOccupancy}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAll();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Name} has an Id of {c.Id}");
                    }
                    ;
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for a chore"):
                    Console.Write("Chore Id: ");
                    int choreId = int.Parse(Console.ReadLine());

                    Chore chore = choreRepo.GetById(choreId);

                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore name: ");
                    string choreName = Console.ReadLine();

                    Chore choreToAdd = new Chore()
                    {
                        Name = choreName,
                    };

                    choreRepo.Insert(choreToAdd);

                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for roommate"):
                    Console.Write("Roommate Id: ");
                    int roommateId = int.Parse(Console.ReadLine());

                    Roommate roommate = roommateRepo.GetById(roommateId);

                    Console.WriteLine($"{roommate.FirstName} pays {roommate.RentPortion}% of rent to occupy the {roommate.Room.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all unassigned chores"):
                    List <Chore> unassignedChores = choreRepo.UnassignedChores();
                    foreach (Chore c in unassignedChores)
                    {
                        Console.WriteLine($"ID: {c.Id} - Chore: {c.Name}");
                    }
                    ;
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Assign chore to roommate"):
                    List <Chore>    choresToAssign   = choreRepo.GetAll();
                    List <Roommate> roomatesToAssign = roommateRepo.GetAll();
                    Console.WriteLine("Chore List:");
                    Console.WriteLine("---------------------");
                    foreach (Chore c in choresToAssign)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("");
                    Console.Write("Which chore would you like to assign: ");
                    int choreChoice = int.Parse(Console.ReadLine());

                    Console.WriteLine("Roommate List:");
                    Console.WriteLine("---------------------");
                    foreach (Roommate r in roomatesToAssign)
                    {
                        Console.WriteLine($"{r.Id} - {r.FirstName} {r.LastName}");
                    }
                    Console.WriteLine("");
                    Console.Write($"Which roommate would you like to assign to chore #{choreChoice}? ");
                    int roommateChoice = int.Parse(Console.ReadLine());

                    choreRepo.AssignChore(roommateChoice, choreChoice);

                    Roommate roomie = roommateRepo.GetById(roommateChoice);
                    Chore    chorie = choreRepo.GetById(choreChoice);

                    Console.WriteLine($"The '{chorie.Name}' chore was assigned to {roomie.FirstName} {roomie.LastName}!");

                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Get Chore Count"):
                    List <ChoreCount> choreCount = choreRepo.GetChoreCounts();
                    foreach (ChoreCount c in choreCount)
                    {
                        Console.WriteLine($"{c.Name}: {c.NumberOfChores}");
                    }
                    ;
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                //room case commands
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Name} has an Id of {r.Id} and a max occupancy of {r.MaxOccupancy}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAll();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete a room"):
                    List <Room> deleteOptions = roomRepo.GetAll();
                    foreach (Room d in deleteOptions)
                    {
                        Console.WriteLine($"{d.Id} - {d.Name} Max Occupancy({d.MaxOccupancy})");
                    }
                    Console.WriteLine("Please note you may not delete a room if people are living in it");
                    Console.Write("Which empty room would you like to delete?");
                    int  deletedRoomId = int.Parse(Console.ReadLine());
                    Room deletedRoom   = deleteOptions.FirstOrDefault(d => d.Id == deletedRoomId);

                    roomRepo.Delete(deletedRoomId);

                    Console.WriteLine($"Room has been successful deleted");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;


                //chore case commands
                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Name} has an Id of {c.Id}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.Write("Chore Id: ");
                    int choreId = int.Parse(Console.ReadLine());

                    Chore chore = choreRepo.GetById(choreId);

                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore name: ");
                    string choreName = Console.ReadLine();

                    Chore choreToAdd = new Chore()
                    {
                        Name = choreName,
                    };

                    choreRepo.Insert(choreToAdd);

                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a chore"):
                    List <Chore> choreOptions = choreRepo.GetAll();
                    foreach (Chore c in choreOptions)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }

                    Console.Write("Which chore would you like to update? ");
                    int   selectedChoreId = int.Parse(Console.ReadLine());
                    Chore selectedChore   = choreOptions.FirstOrDefault(c => c.Id == selectedChoreId);

                    Console.Write("New Name: ");
                    selectedChore.Name = Console.ReadLine();

                    choreRepo.Update(selectedChore);

                    Console.WriteLine("Chore has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete a chore"):
                    List <Chore> deleteChores = choreRepo.GetAll();
                    foreach (Chore d in deleteChores)
                    {
                        Console.WriteLine($"{d.Id} - {d.Name}");
                    }
                    Console.Write("Which chore would you like to delete?");
                    int   deletedChoreId = int.Parse(Console.ReadLine());
                    Chore deletedChore   = deleteChores.FirstOrDefault(d => d.Id == deletedChoreId);

                    choreRepo.Delete(deletedChoreId);

                    Console.WriteLine("Chore has been successful deleted");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                //select a roommate by id

                case ("Search for roommate"):
                    Console.Write("Roommate Id: ");
                    int roommateId = int.Parse(Console.ReadLine());

                    Roommate roommate = roommateRepo.GetById(roommateId);

                    Console.WriteLine($"{roommate.Id} - {roommate.FirstName} {roommate.LastName} pays {roommate.RentPortion}% of the rent. They live in {roommate.Room.Name}.");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;



                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateChoreRepo  rcRepo       = new RoommateChoreRepo(CONNECTION_STRING);

            //Console.WriteLine("Getting All Rooms:");
            //Console.WriteLine();

            //List<Room> allRooms = roomRepo.GetAll();

            //foreach (Room room in allRooms)
            //{
            //    Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            //}

            //Console.WriteLine("----------------------------");
            //Console.WriteLine("Getting Room with Id 1");

            //Room singleRoom = roomRepo.GetById(1);

            //Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            //Room bathroom = new Room
            //{
            //    Name = "Bathroom",
            //    MaxOccupancy = 1
            //};

            //roomRepo.Insert(bathroom);

            //Console.WriteLine("-------------------------------");
            //Console.WriteLine($"Added the new Room with id {bathroom.Id}");

            //Room washroom = new Room
            //{
            //    Id = 7,
            //    Name = "Washroom",
            //    MaxOccupancy = 2
            //};

            //roomRepo.Update(washroom);

            while (true)
            {
                Console.WriteLine();
                int selection = Menu();
                switch (selection)
                {
                case 1:
                    List <Roommate> allRoommates = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine(@$ "{roommate.Firstname} {roommate.Lastname} {roommate.RentPortion}
Living in the {roommate.Room.Name}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter room id to return who lives in that room");
                    string          roomyRoomString = Console.ReadLine();
                    int             roomyRoomId     = int.Parse(roomyRoomString);
                    List <Roommate> roomies         = roommateRepo.GetAllWithRoom(roomyRoomId);
                    foreach (Roommate roommate in roomies)
                    {
                        Console.WriteLine($"{roommate.Firstname} {roommate.Lastname}");
                    }
                    break;

                case 3:
                    Console.WriteLine("Roommate First Name:");
                    string FirstName = Console.ReadLine();
                    Console.WriteLine("Roommate Last Name:");
                    string LastName = Console.ReadLine();
                    Console.WriteLine("Rent Portion:");
                    string   RentString = Console.ReadLine();
                    int      RentInt    = Int32.Parse(RentString);
                    DateTime todaysDate = DateTime.Now;
                    Console.WriteLine("Room Id:");
                    string   RoomIdString = Console.ReadLine();
                    int      RoomIdInt    = Int32.Parse(RoomIdString);
                    Room     singleRoom   = roomRepo.GetById(RoomIdInt);
                    Roommate newRoomy     = new Roommate()
                    {
                        Firstname   = FirstName,
                        Lastname    = LastName,
                        RentPortion = RentInt,
                        MovedInDate = todaysDate,
                        Room        = singleRoom
                    };
                    roommateRepo.Insert(newRoomy);
                    break;

                case 4:
                    Console.WriteLine("Enter Roommate Id to Update:");
                    string   roomyString   = Console.ReadLine();
                    int      roomyInt      = Int32.Parse(roomyString);
                    Roommate roomyToUpdate = roommateRepo.GetById(roomyInt);

                    Console.WriteLine($"Enter updated roomy First Name from {roomyToUpdate.Firstname}:");
                    string firstName = Console.ReadLine();

                    Console.WriteLine($"Enter updated roomy Last Name from {roomyToUpdate.Lastname}");
                    string lastName = Console.ReadLine();

                    Console.WriteLine($"Update Rent Portion from {roomyToUpdate.RentPortion}");
                    string RentStringed = Console.ReadLine();
                    int    RentInted    = Int32.Parse(RentStringed);

                    Console.WriteLine($"Enter updated room Id from {roomyToUpdate.Room.Id}");
                    string   RoomyIdString    = Console.ReadLine();
                    int      RoomyIdInt       = Int32.Parse(RoomyIdString);
                    Room     updateSingleRoom = roomRepo.GetById(RoomyIdInt);
                    Roommate updatedRoomy     = new Roommate
                    {
                        Firstname   = firstName,
                        Lastname    = lastName,
                        RentPortion = RentInted,
                        MovedInDate = roomyToUpdate.MovedInDate,
                        Room        = updateSingleRoom,
                        Id          = roomyToUpdate.Id
                    };
                    roommateRepo.Update(updatedRoomy);

                    break;

                case 5:
                    Console.WriteLine("Enter Roommate id to kick from the house:");
                    string stringOfRoomyKick = Console.ReadLine();
                    int    intOfRoomyKick    = Int32.Parse(stringOfRoomyKick);
                    roommateRepo.Delete(intOfRoomyKick);
                    break;

                case 6:
                    Console.WriteLine("Enter roommate Id of roomy who needs some chores:");
                    string   rmString  = Console.ReadLine();
                    int      rmInt     = int.Parse(rmString);
                    Roommate lazyRoomy = roommateRepo.GetById(rmInt);

                    Console.WriteLine("Enter the name of the chore to complete");
                    string choreName = Console.ReadLine();
                    Chore  newChore  = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(newChore);
                    Chore choreSelected = choreRepo.GetWithChoreName(newChore.Name);
                    rcRepo.InsertRC(lazyRoomy, choreSelected);
                    break;

                case 0:
                    Console.WriteLine("Goodbye");
                    return;

                default:
                    throw new Exception("Something went wrong...invalid selection");
                }
            }
Exemple #8
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);
                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.WriteLine("Chore Id: ");
                    int   choreId = int.Parse(Console.ReadLine());
                    Chore chore   = choreRepo.GetById(choreId);
                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.WriteLine("Chore name: ");
                    string choreName  = Console.ReadLine();
                    Chore  choreToAdd = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(choreToAdd);
                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for roommate"):
                    Console.WriteLine("Roommate Id: ");
                    int      roommateId = int.Parse(Console.ReadLine());
                    Roommate roommate   = roommateRepo.GetById(roommateId);
                    Console.WriteLine($"{roommate.Firstname}:");
                    Console.WriteLine($"    Rent Portion:{roommate.RentPortion}");
                    Console.WriteLine($"    Room: {roommate.Room.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Unassigned chores"):
                    List <Chore> unassignedchores = choreRepo.UnassignedChores();
                    foreach (Chore c in unassignedchores)
                    {
                        Console.WriteLine(c.Name);
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Assign chore to roommate"):
                    List <Chore>    choreList    = choreRepo.GetAll();
                    List <Roommate> roommateList = roommateRepo.GetAll();
                    foreach (Chore c in choreList)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Please enter the id of the chore.");
                    int   choreIdToAdd = int.Parse(Console.ReadLine());
                    Chore chore1       = choreRepo.GetById(choreIdToAdd);
                    foreach (Roommate r in roommateList)
                    {
                        Console.WriteLine($"{r.Id} - {r.Firstname} {r.Lastname}");
                    }
                    Console.WriteLine("Please enter the id of the roommate.");
                    int      roommateIdToAdd = int.Parse(Console.ReadLine());
                    Roommate roommate1       = roommateRepo.GetById(roommateIdToAdd);
                    choreRepo.assignChore(roommateIdToAdd, choreIdToAdd);
                    Console.WriteLine($"{roommate1.Firstname} {roommate1.Lastname} has been assigned to {chore1.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAll();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete room"):
                    List <Room> allRooms = roomRepo.GetAll();
                    foreach (Room r in allRooms)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name}");
                    }
                    Console.WriteLine("Selecet the Id of the room to delete.");
                    int roomToDelete = int.Parse(Console.ReadLine());
                    roomRepo.Delete(roomToDelete);
                    break;

                case ("Update a chore"):
                    List <Chore> choreOptions = choreRepo.GetAll();
                    foreach (Chore c in choreOptions)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Which chore would you like to update?");
                    int   selectedChoreId = int.Parse(Console.ReadLine());
                    Chore selectedChore   = choreOptions.FirstOrDefault(c => c.Id == selectedChoreId);
                    Console.WriteLine("New Name: ");
                    selectedChore.Name = Console.ReadLine();
                    choreRepo.Update(selectedChore);
                    Console.WriteLine("Chore has been successfully updates.");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete chore"):
                    List <Chore> allChore = choreRepo.GetAll();
                    foreach (Chore c in allChore)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Selecet the Id of the chore to delete.");
                    int choreToDelete = int.Parse(Console.ReadLine());
                    choreRepo.Delete(choreToDelete);
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Name} has an Id of {r.Id} and a max occupancy of {r.MaxOccupancy}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Name} has an Id of {c.Id}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore name: ");
                    string choreName = Console.ReadLine();

                    Chore choreToAdd = new Chore()
                    {
                        Name = choreName
                    };

                    choreRepo.Insert(choreToAdd);
                    break;

                case ("Search for roommate"):
                    Console.Write("Roommate Id: ");
                    int Roommateid = int.Parse(Console.ReadLine());

                    Roommate roommate = roommateRepo.GetById(Roommateid);

                    Console.WriteLine($"Name: {roommate.FirstName}, Rent Portion: {roommate.RentPortion}%, Room: {roommate.RoomName}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAllRooms();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAllChores();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.Write("Chore Id: ");
                    int   choreId = int.Parse(Console.ReadLine());
                    Chore chore   = choreRepo.GetById(choreId);
                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore Name");
                    string choreName  = Console.ReadLine();
                    Chore  choreToAdd = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(choreToAdd);
                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show unassigned chores"):
                    List <Chore> unassignedChores = choreRepo.GetUnassignedChores();
                    foreach (Chore c in unassignedChores)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Assign a chore"):
                    Console.WriteLine();
                    List <Chore> choreToAssign = choreRepo.GetUnassignedChores();
                    Console.WriteLine(" - - - Currently unassigned chores - - - ");
                    foreach (Chore c in choreToAssign)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write(" \n Which chore would you like to assign? ");
                    int choreChosen = int.Parse(Console.ReadLine());
                    Console.WriteLine();

                    List <Roommate> roommateToAssign = roommateRepo.GetAllRoommates();
                    foreach (Roommate r in roommateToAssign)
                    {
                        Console.WriteLine($"{r.Id} - {r.FirstName}");
                    }
                    Console.Write(" \n Which roommate would you like to assign the chore to? ");
                    int roommateChosen = int.Parse(Console.ReadLine());
                    Console.WriteLine();
                    choreRepo.AssignChore(roommateChosen, choreChosen);
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show chore counts"):
                    List <string> choreCounts = choreRepo.GetChoreCounts();
                    foreach (string c in choreCounts)
                    {
                        Console.WriteLine(c);
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAllRooms();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

            //Console.WriteLine("Getting All Roommates:");
            //Console.WriteLine();

            //List<Room> allRooms = roomRepo.GetAll();


            //foreach (Room room in allRooms)
            //{
            //    Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            //}

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);

            //Console.WriteLine("Getting All Rooms:");
            //Console.WriteLine();

            //List<Roommate> allRoommatesWithRoom = roommateRepo.GetAllWithRoom();



            //            foreach (var roommate in allRoommatesWithRoom)
            //            {
            //                Console.WriteLine(@$"{roommate.Id}
            //{roommate.FirstName} {roommate.LastName}
            //{roommate.RentPortion} {roommate.MoveInDate}
            //{roommate.Room.Name}");
            //            }

            while (true)
            {
                Console.WriteLine();

                int selection = Menu();
                switch (selection)
                {
                case 0:
                    Console.WriteLine("Goodbye");
                    return;

                default:
                    throw new Exception("Something went wrong...invalid selection");

                case 1:
                    List <Room> allRooms = roomRepo.GetAll();
                    foreach (Room room in allRooms)
                    {
                        Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
                    }
                    break;

                case 2:
                    Console.Write($"Enter the name of the new room to add: ");
                    string newName = Console.ReadLine();
                    Console.Write($"Enter {newName}'s Max Occupancy: ");
                    int newMaxOcc = Int32.Parse(Console.ReadLine());


                    Room AddedRoom = new Room
                    {
                        Name         = newName,
                        MaxOccupancy = newMaxOcc
                    };

                    roomRepo.Insert(AddedRoom);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new Room {AddedRoom.Name} with id {AddedRoom.Id}");
                    break;

                case 3:
                    Console.Write($"Enter Id of a room you want to delete: ");
                    int roomId = Int32.Parse(Console.ReadLine());

                    roomRepo.Delete(roomId);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Deleted the room with id {roomId}");
                    break;

                case 4:
                    Console.Write($"Enter the id of the room you'd like to edit: ");
                    int UpdatedRoomId = Int32.Parse(Console.ReadLine());
                    var selectedRoom  = roomRepo.GetById(UpdatedRoomId);

                    Console.Write($"Enter a new name for {selectedRoom.Name} to update database: ");
                    string UpdatedName = Console.ReadLine();

                    Console.Write($"Enter a new Max Occupancy for {selectedRoom.Name} to update database: ");
                    int UpdatedMaxOcc = Int32.Parse(Console.ReadLine());

                    Room UpdatedRoom = new Room
                    {
                        Id           = UpdatedRoomId,
                        Name         = UpdatedName,
                        MaxOccupancy = UpdatedMaxOcc
                    };

                    roomRepo.Update(UpdatedRoom);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Updated the {UpdatedRoom}");
                    break;

                case 5:     //List all roommates
                    List <Roommate> allRoommates = roommateRepo.GetAll();
                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine(@$ "
                                Id: {roommate.Id}
                                {roommate.FirstName} {roommate.LastName}
                                Rent Portion: {roommate.RentPortion}
                                Move In Date: {roommate.MoveInDate}
                            ");
                    }
                    break;

                case 6:     //Add a roommate
                    Console.Write($"Enter the name of the new roommate's first name: ");
                    string newFirstName = Console.ReadLine();
                    Console.Write($"Enter the name of the new roommate's last name: ");
                    string newLastName = Console.ReadLine();
                    Console.Write($"Enter {newFirstName}'s Rent share percentage (Enter a number 0-100): ");
                    int         RentPortion   = Int32.Parse(Console.ReadLine());
                    DateTime    MoveInDate    = DateTime.Now;
                    List <Room> allRoomsAgain = roomRepo.GetAll();

                    Console.WriteLine($"Enter {newFirstName}'s room id to rent from the list");
                    foreach (Room room in allRoomsAgain)
                    {
                        Console.WriteLine($"Room Id: {room.Id} Room : {room.Name}:");
                    }
                    Console.Write($"> ");

                    int  NewRoomId          = Int32.Parse(Console.ReadLine());
                    Room newRoomforRoommate = roomRepo.GetById(NewRoomId);


                    Roommate AddedRoommate = new Roommate
                    {
                        FirstName   = newFirstName,
                        LastName    = newLastName,
                        RentPortion = RentPortion,
                        MoveInDate  = MoveInDate,
                        Room        = newRoomforRoommate
                    };

                    roommateRepo.Insert(AddedRoommate);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new Roommate {AddedRoommate.FirstName}{AddedRoommate.LastName}");
                    break;

                case 7:     //Edit a roommate's info

                    List <Roommate> allRoomies = roommateRepo.GetAll();
                    foreach (Roommate roommate in allRoomies)
                    {
                        Console.WriteLine($"Id: {roommate.Id} {roommate.FirstName} {roommate.LastName}");
                    }

                    Console.Write($"Enter the id (listed above) of the roommate you'd like to edit: ");
                    int UpdatedRoommateId = Int32.Parse(Console.ReadLine());
                    var selectedRoommate  = roommateRepo.GetById(UpdatedRoommateId);

                    Console.Write($"Enter a first name for {selectedRoommate.FirstName} to edit the info or type in {selectedRoommate.FirstName} to keep it the same: ");
                    string UpdatedFirstName = Console.ReadLine();

                    Console.Write($"Enter a new last name instead of {selectedRoommate.LastName} or type in {selectedRoommate.LastName} to keep it the same");
                    string UpdatedLastName = Console.ReadLine();

                    Console.Write($"Enter a new rent share percentage (a number 0-100) or type in the current share ({selectedRoommate.RentPortion}) to remain the same: ");
                    int UpdateRentPortion = Int32.Parse(Console.ReadLine());

                    DateTime EditMoveInDate = DateTime.Now;

                    List <Room> allRoomsEncore = roomRepo.GetAll();

                    Console.WriteLine($"Enter a new room id to rent from the list below");
                    foreach (Room room in allRoomsEncore)
                    {
                        Console.WriteLine($"Room Id: {room.Id} Room : {room.Name}:");
                    }
                    Console.Write($"> ");

                    int  EditRoomId             = Int32.Parse(Console.ReadLine());
                    Room updatedRoomforRoommate = roomRepo.GetById(EditRoomId);

                    Roommate UpdatedRoommate = new Roommate
                    {
                        Id          = UpdatedRoommateId,
                        FirstName   = UpdatedFirstName,
                        LastName    = UpdatedLastName,
                        RentPortion = UpdateRentPortion,
                        MoveInDate  = EditMoveInDate,
                        Room        = updatedRoomforRoommate
                    };

                    roommateRepo.Update(UpdatedRoommate);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Updated {UpdatedRoommate.FirstName}{UpdatedRoommate.LastName}'s info");
                    break;

                case 8:     //delete a roommate
                    Console.Write($"Enter Id of a roommate you want to delete: ");
                    int roommateId = Int32.Parse(Console.ReadLine());

                    roomRepo.Delete(roommateId);

                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Deleted the roommate with id {roommateId}");
                    break;

                case 9:    //List all chores
                    List <Chore> allChores = choreRepo.GetAll();
                    foreach (Chore chore in allChores)
                    {
                        Console.WriteLine(@$ "Id: 
{chore.Id}
Name: {chore.Name}");
                    }
                    break;

                case 10:
                    Console.Write($"Enter the name of the new chore to add: ");
                    string newChoreName = Console.ReadLine();

                    Chore AddedChore = new Chore
                    {
                        Name = newChoreName,
                    };
                    choreRepo.Insert(AddedChore);
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new chore '{AddedChore.Name}' with id {AddedChore.Id}");
                    break;
                }
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            RoomRepository  roomRepo  = new RoomRepository(CONNECTION_STRING);
            ChoreRepository choreRepo = new ChoreRepository(CONNECTION_STRING);

            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Name} has an Id of {r.Id} and a max occupancy of {r.MaxOccupancy}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    // Print out name of INSERT room - Id that was set by the INSERT method
                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore name: ");
                    string choreName = Console.ReadLine();

                    Chore choreToAdd = new Chore()
                    {
                        Name = choreName
                    };

                    choreRepo.Insert(choreToAdd);

                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAll();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a chore"):
                    List <Chore> choreOptions = choreRepo.GetAll();
                    foreach (Chore c in choreOptions)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }

                    Console.Write("Which chore would you like to update? ");
                    int   selectedChoreId = int.Parse(Console.ReadLine());
                    Chore selectedChore   = choreOptions.FirstOrDefault(c => c.Id == selectedChoreId);

                    Console.Write("New Chore: ");
                    selectedChore.Name = Console.ReadLine();

                    choreRepo.Update(selectedChore);

                    Console.WriteLine("Chore has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete a room"):
                    List <Room> deleteRoomOptions = roomRepo.GetAll();
                    foreach (Room r in deleteRoomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }
                    Console.Write("Which room would you like to delete? ");
                    int  selectedRoomToDeleteId = int.Parse(Console.ReadLine());
                    Room selectedRoomToDelete   = deleteRoomOptions.FirstOrDefault(r => r.Id == selectedRoomToDeleteId);

                    roomRepo.Delete(selectedRoomToDeleteId);
                    break;

                case ("Delete a chore"):
                    List <Chore> deleteChoreOptions = choreRepo.GetAll();
                    foreach (Chore c in deleteChoreOptions)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Which chore would you like to delete? ");
                    int   selectedChoreToDeleteId = int.Parse(Console.ReadLine());
                    Chore selectedChoreToDelete   = deleteChoreOptions.FirstOrDefault(c => c.Id == selectedChoreToDeleteId);

                    choreRepo.Delete(selectedChoreToDeleteId);
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Name} has an Id of {c.Id}.");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.Write("Chore Id: ");
                    int choreId = int.Parse(Console.ReadLine());

                    Chore chore = choreRepo.GetById(choreId);

                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Exemple #13
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo  = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository rmRepo    = new RoommateRepository(CONNECTION_STRING);

            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    ListAllRooms();
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;


                case ("Show all chores"):
                    ListAllChores();
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;


                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int  id   = int.Parse(Console.ReadLine());
                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.WriteLine("Chore Id: ");
                    int   choreId = int.Parse(Console.ReadLine());
                    Chore chore   = choreRepo.GetById(choreId);
                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for a roommate"):
                    Console.WriteLine("Roommate Id: ");
                    int      roommateId = int.Parse(Console.ReadLine());
                    Roommate roommate   = rmRepo.GetById(roommateId);
                    Console.WriteLine($"{roommate.Id} - {roommate.FirstName} {roommate.LastName} - {roommate.Room.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int  max       = int.Parse(Console.ReadLine());
                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };
                    roomRepo.Insert(roomToAdd);
                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = ListAllRooms("return");
                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);
                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();
                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());
                    roomRepo.Update(selectedRoom);
                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete a room"):
                    ListAllRooms();
                    Console.Write("Which room would you like to delete? ");
                    int deletedRoomId = int.Parse(Console.ReadLine());
                    roomRepo.Delete(deletedRoomId, "Room");
                    Console.WriteLine($"Room has been successfully deleted");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.WriteLine("Chore Name: ");
                    string choreName  = Console.ReadLine();
                    Chore  choreToAdd = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(choreToAdd);
                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a chore"):
                    List <Chore> choreOptions = ListAllChores("return");
                    Console.Write("Which chore would you like to update? ");

                    int   selectedChoreId = int.Parse(Console.ReadLine());
                    Chore selectedChore   = choreOptions.FirstOrDefault(r => r.Id == selectedChoreId);

                    Console.Write("New Name: ");
                    selectedChore.Name = Console.ReadLine();

                    choreRepo.Update(selectedChore);

                    Console.WriteLine($"Chore has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;



                case ("Delete a chore"):
                    ListAllChores();
                    Console.Write("Which chore would you like to delete? ");
                    int deletedChoreId = int.Parse(Console.ReadLine());
                    choreRepo.Delete(deletedChoreId);
                    Console.WriteLine($"Chore has been successfully deleted");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all unassigned chores"):
                    List <Chore> unassignedChores = choreRepo.GetUnassignedChores();
                    foreach (Chore c in unassignedChores)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;



                case ("Assign chore to roommate"):
                    ListAllChores();
                    Console.WriteLine("Select the id of the chore you want to assign.");
                    int             assignChoreId = int.Parse(Console.ReadLine());
                    List <Roommate> roommates     = rmRepo.GetAll();
                    foreach (Roommate r in roommates)
                    {
                        Console.WriteLine($"{r.Id} - {r.FirstName} {r.LastName})");
                    }
                    Console.WriteLine("Select the id of the roommate you want to assign the chore to.");
                    int selectedRmId = int.Parse(Console.ReadLine());
                    choreRepo.AssignChore(selectedRmId, assignChoreId);
                    Console.WriteLine("Chore assigned");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;



                case ("Check the chore assignment count"):
                    List <ChoreCount> counts = choreRepo.GetChoreCounts();
                    foreach (ChoreCount count in counts)
                    {
                        Console.WriteLine($"{count.Name}: {count.Count} chores");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }