Beispiel #1
0
        private static void ReassignChore(ChoreRepository choreRepo, RoommateRepository roommateRepo)
        {
            List <Chore> assignedChores = choreRepo.GetAssignedChores();

            foreach (Chore chore in assignedChores)
            {
                Console.WriteLine($"{chore.Id} - {chore.Name}");
            }
            Console.Write("Chore to reassign: ");
            int choreSelection = int.Parse(Console.ReadLine());

            Roommate roommateChore = roommateRepo.GetRoommateChoreById(choreSelection);

            Console.WriteLine($"This chore is currently assigned to {roommateChore.FirstName}. Who would you like to assign it to?");

            List <Roommate> roommates = roommateRepo.GetAll();

            foreach (Roommate roommate in roommates)
            {
                Console.WriteLine($"{roommate.Id} - {roommate.FirstName}");
            }
            Console.Write("Roommate to be assigned chore: ");
            int roommateSelection = int.Parse(Console.ReadLine());

            choreRepo.ReassignChore(choreSelection, roommateSelection, roommateChore.Id);

            Roommate roommateAssigned = roommateRepo.GetById(roommateSelection);

            Console.WriteLine($"Chore successfully reassigned to {roommateAssigned.FirstName}");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
Beispiel #2
0
        static void AssignRoommateChore(ChoreRepository choreRepo, RoommateRepository roommateRepo)
        {
            Console.WriteLine("----------------------");
            Console.WriteLine("Chores");
            Console.WriteLine("----------------------");
            List <Chore> chores = choreRepo.GetAll();

            chores.ForEach(c => Console.WriteLine($"{c.Id} - {c.Name}"));
            Console.WriteLine("");
            Console.Write("Enter chore Id: ");
            int choreId = int.Parse(Console.ReadLine());

            List <Roommate> roommates = roommateRepo.GetAll();

            Console.WriteLine("");
            Console.WriteLine("----------------------");
            Console.WriteLine("Roommates");
            Console.WriteLine("----------------------");
            roommates.ForEach(r => Console.WriteLine($"{r.Id} - {r.Firstname}"));
            Console.WriteLine("");
            Console.Write("Enter roommate Id: ");
            int roommateId = int.Parse(Console.ReadLine());

            Chore    selectedChore    = chores.Find(c => c.Id == choreId);
            Roommate selectedRoommate = roommates.Find(r => r.Id == roommateId);

            choreRepo.AssignChore(roommateId, choreId);
            Console.WriteLine($"{selectedRoommate.Firstname} is assign to {selectedChore.Name}");
            ContinueMenu();
        }
Beispiel #3
0
        static void AssignChoreToRoommate(ChoreRepository choreRepo, RoommateRepository roommateRepo)
        {
            List <Chore>    chores    = choreRepo.GetAll();
            List <Roommate> roommates = roommateRepo.GetAll();

            foreach (Chore c in chores)
            {
                Console.WriteLine($"{c.Id} - {c.Name}");
            }
            Console.Write("Select chore: ");
            int choreChoice = int.Parse(Console.ReadLine());

            foreach (Roommate r in roommates)
            {
                Console.WriteLine($"{r.Id} - {r.FirstName}");
            }
            Console.Write("Select roommate: ");
            int roommateChoice = int.Parse(Console.ReadLine());

            choreRepo.AssignChore(choreChoice, roommateChoice);

            Chore    chore    = choreRepo.GetById(choreChoice);
            Roommate roommate = roommateRepo.GetById(roommateChoice);

            Console.WriteLine($"{chore.Name} has been assigned to {roommate.FirstName}");
            Console.Write("Press any key to continue");
            Console.ReadKey();
        }
Beispiel #4
0
        static void PrintRoommates(RoommateRepository roommateRepo)
        {
            List <Roommate> roommates = roommateRepo.GetAll();

            foreach (Roommate rm in roommates)
            {
                Console.WriteLine($"{rm.Id} - {rm.Firstname} - {rm.RentPortion}");
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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}");
            }
            Room bathroom = new Room
            {
                Name         = "Bathroom",
                MaxOccupancy = 1
            };

            roomRepo.Insert(bathroom);

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


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

            Console.WriteLine("Deleting");

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Room}");
                Console.WriteLine();
                // Console.WriteLine("Getting Roommate with specific Id");

                // Roommate singleRoommate = roommateRepo.GetById(1);
                //Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname}");
            }
            Roommate Aaron = new Roommate
            {
                Firstname = "Aaron"
            };

            roommateRepo.Insert(Aaron);
            Console.WriteLine($"Added new roommate: {Aaron.Firstname}");
        }
Beispiel #6
0
        static void GetAllRoommates(RoommateRepository roommateRepo)
        {
            Console.WriteLine("\nGetting All Roommates");
            Console.WriteLine("---------------------");
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}");
            }
        }
Beispiel #7
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}");
        }
Beispiel #8
0
        static void ListAllRoommates()
        {
            // Get list of roommates
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("----------- Get Roommate List -------------");
            List <Roommate> AllRoommates = roommateRepo.GetAll();

            Console.WriteLine("First Name \t Last name \t Rent Portion \t Move In Date \t Room Name \t Max Occupancy");
            foreach (Roommate roommate in AllRoommates)
            {
                Console.WriteLine($"{roommate.Id}\t{roommate.FirstName}\t{roommate.LastName}\t{roommate.RentPortion}\t{roommate.MoveInDate}\t{roommate.Room.Name}\t{roommate.Room.MaxOccupancy}");
            }
            ;
        }
        private static void ViewAllRoommates(RoomRepository roomRepo, RoommateRepository roommateRepo)
        {
            Console.Clear();
            HouseBot();
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.MoveInDate} {roommate.RentPortion}");
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
            RoommatePage(roomRepo, roommateRepo);
        }
Beispiel #10
0
        static void DeleteRoommate()
        {
            // Delete Roommate
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("---------- Removing a Roommate --------------");
            Console.WriteLine("Enter the ID of the Roommate you'd like to Delete To Proceed:");
            ListAllRoommates();
            roommateRepo.Delete(Int32.Parse(Console.ReadLine()));
            // Get list of roommates
            Console.WriteLine("----------- Here's the Updated Roommate List after your deletion -------------");
            List <Roommate> UpdatedRoommates = roommateRepo.GetAll();

            Console.WriteLine("First Name \t Last name \t Rent Portion \t Move In Date \t Room Name \t Max Occupancy");
            foreach (Roommate roommate in UpdatedRoommates)
            {
                Console.WriteLine($"{roommate.FirstName}\t{roommate.LastName}\t{roommate.RentPortion}\t{roommate.MoveInDate}\t{roommate.Room.Name}\t{roommate.Room.MaxOccupancy}");
            }
        }
        private static void UpdateARoommate(RoomRepository roomRepo, RoommateRepository roommateRepo)
        {
            string          message      = "Which roommate would you like to update?";
            List <Roommate> allRoommates = roommateRepo.GetAll();

            int id;

            do
            {
                id = intMooseSays(message, allRoommates);
            }while (!allRoommates.Any(rm => rm.Id == id));

            Console.Clear();
            Roommate roommateToUpdate = RoommateValueUpdater(id, roommateRepo);

            roommateRepo.Update(roommateToUpdate);
            Console.Clear();
            RoommatePage(roomRepo, roommateRepo);
        }
        private static void DeleteARoommate(RoomRepository roomRepo, RoommateRepository roommateRepo)
        {
            string          message      = "Who's been voted out?";
            List <Roommate> allRoommates = roommateRepo.GetAll();


            int id;

            do
            {
                id = intMooseSays(message, allRoommates);
            }   while (!allRoommates.Any(rm => rm.Id == id));


            roommateRepo.Delete(id);

            Console.Clear();
            RoommatePage(roomRepo, roommateRepo);
        }
        private static void ViewSingleRoommate(RoomRepository roomRepo, RoommateRepository roommateRepo)
        {
            int choice;

            Console.Clear();
            HouseBot();
            Console.WriteLine("Enter the index of the Roommate you'd like to view");
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname}");
            }

            do
            {
                choice = getChoice();
            } while (!allRoommates.Any(rm => rm.Id == choice));


            Roommate singleRoommate = roommateRepo.GetById(choice);

            Console.WriteLine($"{singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.RentPortion} {singleRoommate.MoveInDate}");

            Console.WriteLine("Would you like to view another?");
            string YesNo = getYesNo();

            if (YesNo == "y")
            {
                Console.Clear();
                ViewSingleRoommate(roomRepo, roommateRepo);
            }
            else
            {
                Console.Clear();
                RoommatePage(roomRepo, roommateRepo);
            }
        }
Beispiel #14
0
            static void assignChore(ChoreRepository choreRepo, RoommateRepository roommateRepo)
            {
                List <Chore> proposedChores = choreRepo.GetAll();

                foreach (Chore c in proposedChores)
                {
                    Console.WriteLine($"{c.Id} - {c.Name}");
                }
                Console.Write("Select the Id of the chore you want ");
                int chosenChore = int.Parse(Console.ReadLine());

                Console.WriteLine("-------------------------");
                List <Roommate> proposedRoommates = roommateRepo.GetAll();

                foreach (Roommate r in proposedRoommates)
                {
                    Console.WriteLine($"{r.Id}) {r.Firstname} {r.Lastname}");
                }
                Console.Write("Select the Id of the roommate to assign ");
                int chosenRoommate = int.Parse(Console.ReadLine());

                choreRepo.AssignChore(chosenRoommate, chosenChore);
            }
Beispiel #15
0
        //returns value of a type Roommate at the particular index that user chooses from the roommates list;
        private Roommate ChooseRoommate(string prompt = null)
        {
            if (prompt == null)
            {
                prompt = "Please choose a Roommate";
            }

            Console.WriteLine(prompt);

            List <Roommate> roommates = _roommateRepository.GetAll();

            for (int i = 0; i < roommates.Count; i++)
            {
                Roommate roommate = roommates[i];
                Console.WriteLine($"{i + 1} {roommate.Firstname} {roommate.Lastname}");
            }
            Console.Write("> ");

            // reads the user's roommate input
            string input = Console.ReadLine();

            try
            {
                // if the choice is not valid choice and throws an exception (ie not in the list of roommates or not a valid int)
                // will trigger catch
                // if able to parse this will parse the string choice into proper int
                int choice = int.Parse(input);
                // return the value of roommates list at that particular index - 1 since added 1 to i previously in order to not show user 0 as option;
                return(roommates[choice - 1]);
            }
            catch (Exception ex)
            {
                //c atch this exception and display this message and return null
                Console.WriteLine("Invalid Selection");
                return(null);
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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("----------------------------");
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("Getting All Roommatess:");
            Console.WriteLine();

            List <Roommate> allRoommatess = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommatess)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} lives in {roommate.Room.Name}");
            }

            Console.WriteLine("----------------------------");
            Console.WriteLine("roomate with id of 1");

            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} lives in {singleRoommate.Room.Name}");



            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 UpdatedRoom = new Room
            {
                Name         = "Attic",
                MaxOccupancy = 1,
                Id           = 5
            };

            roomRepo.Update(UpdatedRoom);

            roomRepo.Delete(9);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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 updatedBathroom = new Room
             * {
             * Name = "Linen Closet",
             * MaxOccupancy = 1,
             * Id = bathroom.Id
             * };
             * roomRepo.Update(updatedBathroom);
             *
             * allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             */



            /*
             * roomRepo.Delete(17);
             *
             * allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             */
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            List <Roommate>    allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}");
            }

            /*
             * Room singleRoommate = allRoommates.GetById(1);
             *
             * Console.WriteLine($"{singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.room.Name}");
             */
            List <Room> someRooms = roomRepo.GetAll();
            Room        aRoom     = someRooms.First();

            Roommate newRoommate = new Roommate()
            {
                Firstname   = "Carrie",
                Lastname    = "Wilson",
                RentPortion = 76,
                MovedInDate = DateTime.Now.AddDays(-1),
                Room        = aRoom
            };

            // roommateRepo.Insert(newRoommate);

            List <Roommate> roommates = roommateRepo.GetAllWithRoom(3);
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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("----------------------------");

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("getting all the roommates");
            Console.WriteLine();
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}");
            }

            /*
             * Console.WriteLine("----------------------------");
             *
             * Console.WriteLine("Getting Room with Id 1");
             *
             * Room singleRoom = roomRepo.GetById(1);
             *
             * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");
             */

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

            Roommate roommate1 = roommateRepo.GetById(1);

            Console.WriteLine($"{roommate1.Firstname} {roommate1.Lastname} {roommate1.Room}");
            Console.WriteLine("----------------------------");

            // getting roommates based on roomId

            Console.WriteLine("getting all the roommates and all their room info");
            List <Roommate> allRoommatesWithRoom = roommateRepo.GetRoommatesByRoomId(1);

            foreach (Roommate roommateWithRoom in allRoommatesWithRoom)
            {
                Console.WriteLine($"{roommateWithRoom.Id}: {roommateWithRoom.Firstname} {roommateWithRoom.Lastname} is assigned {roommateWithRoom.Room.Name}; \n pays {roommateWithRoom.RentPortion} move-in-date: {roommateWithRoom.MovedInDate}");
            }
            ;
            Console.WriteLine("----------------------------");

            Roommate newRoommate = new Roommate
            {
                Firstname   = "pablo",
                Lastname    = "nuts",
                MovedInDate = new DateTime(2020, 2, 22),
                RentPortion = 12,
                Room        = roomRepo.GetById(1)
            };

            //roommateRepo.Insert(newRoommate);
            //update
            roommateRepo.Update(newRoommate);
            Console.WriteLine($"updated juan to {newRoommate.Firstname}");
            Console.WriteLine("----------------------------");

            roommateRepo.Delete(2);

            /*
             * Room bathroom = new Room
             * {
             *  Name = "Bathroom",
             *  MaxOccupancy = 1
             * };
             *
             * roomRepo.Insert(bathroom);
             *
             */


            /*
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"Added the new Room with id {bathroom.Id}");
             *
             * bathroom.MaxOccupancy = 3;
             *
             * roomRepo.Update(bathroom);
             *
             *
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"updated the room to have max occupancy of {bathroom.MaxOccupancy}");
             */


            /*
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             * Console.WriteLine("-------------------------------");
             *
             * roomRepo.Delete(bathroom.Id);
             */
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            // ROOM CALLS
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

            // GET ALL ROOMS
            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}");
            }

            // GET ROOM BY ID
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");
            Room singleRoom = roomRepo.GetById(1);

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

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

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

            // UPDATE ROOM
            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);
            Room bathroomFromDb = roomRepo.GetById(bathroom.Id);

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

            //DELETE ROOM
            Console.WriteLine("-------------------------------");
            roomRepo.Delete(bathroom.Id);
            allRooms = roomRepo.GetAll();
            foreach (Room room in allRooms)
            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }


            // ROOMMATE CALLS
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName} moved in on {roommate.MoveInDate} and pays {roommate.RentPortion} per month");
            }

            // GET ROOMMATE BY ID
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommate with Id 1");
            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id}. {singleRoommate.FirstName} {singleRoommate.LastName}");

            // GET ROOMMATE WITH ROOM
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommates with Room");
            List <Roommate> roommatesRooms = roommateRepo.GetAllWithRoom(5);

            foreach (Roommate roommate in roommatesRooms)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName} lives in room {roommate.Room.Id}");
            }

            // CREATE NEW ROOMMATE
            Roommate rick = new Roommate
            {
                FirstName   = "Big",
                LastName    = "Rick",
                RentPortion = 10,
                MoveInDate  = DateTime.Now,
                Room        = roomRepo.GetById(4)
            };

            roommateRepo.Insert(rick);
            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Roommate with id {rick.Id}");

            // UPDATE ROOMMATE
            rick.LastName = "Ricky";
            roommateRepo.Update(rick);

            Roommate rickFromDb = roommateRepo.GetById(rick.Id);

            Console.WriteLine($"{rickFromDb.Id}. {rickFromDb.FirstName} {rickFromDb.LastName}");

            //DELETE ROOMMATE
            Console.WriteLine("-------------------------------");
            roommateRepo.Delete(4);

            allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName}");
            }
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(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}");


            // >>>>>>>>>>>>>>>>
            // 18. Write some code in Program.Main to test the Update method.
            Room kitchen = new Room
            {
                Name         = "La Cocina",
                MaxOccupancy = 1
            };

            roomRepo.Insert(kitchen);

            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Room with id {kitchen.Id} and name of {kitchen.Name}");

            // >>>>>>>>>>>>>>>>>
            // >>>>>>>>>>>>>>>>
            // 20. Write some code in Program.Main to test the Delete method.
            roomRepo.Delete(kitchen.Id);

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

            // >>>>>>>>>>>>>>>>>>>>>>>.
            // >>>>>>>>>>>>>>>>>>>>>>>.
            // >>>>>>>>>>>>>>>>>>>>>>>.
            Console.WriteLine("-------------------------------");
            Console.WriteLine("ROOMATE!!");

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roomy in allRoommates)
            {
                Console.WriteLine($"{roomy.Id}, {roomy.Firstname} {roomy.Lastname}, {roomy.MoveInDate}");
            }

            foreach (roommatesByRoom roomy in allRoommates)
            {
                Console.WriteLine($"{roomy.Id}, {roomy.Firstname} {roomy.Lastname}, {roomy.MoveInDate}");
            }
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            /* RoomRepository roomRepo = new RoomRepository(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}");
             * Console.WriteLine("-------------------------------");
             * bathroom.Name = "Outhouse";
             * bathroom.MaxOccupancy = 1;
             *
             * roomRepo.Update(bathroom);
             * Room UpdateTest = roomRepo.GetById(bathroom.Id);
             * Console.WriteLine($"Updated: {UpdateTest.Id} {UpdateTest.Name} {UpdateTest.MaxOccupancy}");
             * Console.WriteLine("-------------------------------");
             * roomRepo.Delete(bathroom.Id);
             *
             * List<Room> allRooms2 = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms2)
             * {
             *   Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }*/



            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            int  userEntry      = 1;
            bool mainWhileCheck = true;

            while (mainWhileCheck != false)
            {
                Console.WriteLine("Welcome to Roommate Manager!");
                Console.WriteLine("Choose an option below:");
                Console.WriteLine("");
                Console.WriteLine("1) Get all Roommates");
                Console.WriteLine("2) Get Roommate by Id/Edit");
                Console.WriteLine("3) Get First Roommate by Room");
                Console.WriteLine("4) Get Roommates by Room");
                Console.WriteLine("5) Add new Rommmate");

                Console.WriteLine("6) Delete a Roommate");
                Console.WriteLine("0) Exit");
                Console.WriteLine("");
                userEntry = int.Parse(Console.ReadLine());
                Console.WriteLine("");
                if (userEntry == 0)
                {
                    mainWhileCheck = false;
                    break;
                }
                else if (userEntry == 1)
                {
                    Console.WriteLine("Getting All Roommates:");
                    Console.WriteLine();

                    List <Roommate> allRoommates = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}");
                    }
                    Console.WriteLine("----------------------------");
                }
                else if (userEntry == 2)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the id of the roommate you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());

                    Console.WriteLine($"Getting Roommate with Id {byIdEntry}");

                    Roommate singleRoommate = roommateRepo.GetById(byIdEntry);

                    Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.RentPortion} {singleRoommate.MovedInDate} {singleRoommate.Room}");
                    Console.WriteLine("----------------------------");

                    string editCheck = "a";
                    bool   editWhile = true;
                    Console.WriteLine("");
                    Console.Write("Do you want to Edit this Entry Y/N:");
                    editCheck = Console.ReadLine();
                    Console.WriteLine("");
                    if (editCheck == "y" || editCheck == "Y")
                    {
                        int editSelect = 1;
                        while (editWhile == true)
                        {
                            Console.WriteLine("What do you want to edit:");
                            Console.WriteLine("");
                            Console.WriteLine("1) First Name");
                            Console.WriteLine("2) Last Name");
                            Console.WriteLine("3) Rent Portion");
                            Console.WriteLine("4) Move in Date");
                            Console.WriteLine("5) Assigned Room Id");
                            Console.WriteLine("0) Edit Complete");

                            editSelect = int.Parse(Console.ReadLine());

                            if (editSelect == 0)
                            {
                                editWhile = false;
                            }
                            else if (editSelect == 1)
                            {
                                Console.WriteLine($"The entry's First Name is {singleRoommate.Firstname}. What would you like to change it to?");
                                singleRoommate.Firstname = Console.ReadLine();
                                Console.WriteLine("");
                            }
                            else if (editSelect == 2)
                            {
                                Console.WriteLine($"The entry's Last Name is {singleRoommate.Lastname}. What would you like to change it to?");
                                singleRoommate.Lastname = Console.ReadLine();
                            }
                            else if (editSelect == 3)
                            {
                                Console.WriteLine($"The entry's Rent Portion is {singleRoommate.RentPortion}. What would you like to change it to?");
                                singleRoommate.RentPortion = int.Parse(Console.ReadLine());
                            }
                            else if (editSelect == 4)
                            {
                                Console.WriteLine($"The entry's Move in Day is {singleRoommate.MovedInDate}. What would you like to change it to? (Year, Month, Day)");
                                singleRoommate.MovedInDate = DateTime.Parse(Console.ReadLine());
                            }
                            else if (editSelect == 5)
                            {
                                Console.WriteLine($"The entry's Assigned Room Id is {singleRoommate.RoomId}. What would you like to change it to?");
                                singleRoommate.RoomId = int.Parse(Console.ReadLine());
                            }
                        }
                        roommateRepo.Update(singleRoommate);
                        Roommate UpdatedTest = roommateRepo.GetById(singleRoommate.Id);
                        Console.WriteLine($"Updated: {UpdatedTest.Id} {UpdatedTest.Firstname} {UpdatedTest.Lastname} {UpdatedTest.RentPortion} {UpdatedTest.MovedInDate}");
                        Console.WriteLine("-------------------------------");
                        Console.WriteLine("");
                    }
                    else
                    {
                        Console.WriteLine("");
                    }
                }
                else if (userEntry == 3)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the Roomid of the roommate you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());
                    Console.WriteLine($"Getting Latest Roommate with RoomId {byIdEntry}");
                    Roommate singleRoommate2 = roommateRepo.GetByRoom(byIdEntry);

                    Console.WriteLine($"{singleRoommate2.Id} {singleRoommate2.Firstname} {singleRoommate2.Lastname} {singleRoommate2.RentPortion} {singleRoommate2.MovedInDate} {singleRoommate2.Room.Name} {singleRoommate2.Room.MaxOccupancy} {singleRoommate2.Room.MaxOccupancy}");
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("");
                }
                else if (userEntry == 4)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the Roomid of the roommates you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());
                    Console.WriteLine($"Getting Roommates with RoomId {byIdEntry}");
                    List <Roommate> allRoommatesByRoom = roommateRepo.GetAllWithRoom(byIdEntry);

                    foreach (Roommate roommate in allRoommatesByRoom)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room.Name}");
                    }
                    Console.WriteLine("");
                }
                else if (userEntry == 5)
                {
                    Roommate roomy1 = new Roommate
                    {
                        Firstname   = "Matt",
                        Lastname    = "Patt",
                        RentPortion = 40,
                        MovedInDate = new DateTime(2020, 09, 15),
                        Room        = null,
                        RoomId      = 3
                    };
                    Console.WriteLine("");
                    Console.WriteLine("Input information for a new Roommate:");
                    Console.Write("First Name:");
                    roomy1.Firstname = Console.ReadLine();
                    Console.Write("Last Name:");
                    roomy1.Lastname = Console.ReadLine();
                    Console.Write("Rent Portion:");
                    roomy1.RentPortion = int.Parse(Console.ReadLine());
                    Console.Write("Move In Date (Year, Month, Day):");
                    roomy1.MovedInDate = DateTime.Parse(Console.ReadLine());
                    Console.Write("Assigned Room Id:");
                    roomy1.RoomId = int.Parse(Console.ReadLine());

                    Console.Write("Press any key to submit the Roommate:");
                    Console.ReadLine();
                    roommateRepo.Insert(roomy1);
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new Roommate with id {roomy1.Id}");
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine("");
                }
                else if (userEntry == 6)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Which Roommate would you like to Delete?");
                    List <Roommate> allRoommates = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine($"{roommate.Id}) {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}");
                    }
                    roommateRepo.Delete(int.Parse(Console.ReadLine()));

                    List <Roommate> allRoommates2 = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates2)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.RoomId}");
                    }
                    Console.WriteLine("");
                }
            }
        }
Beispiel #22
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");
                }
            }
Beispiel #23
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

            //GET ALL ROOMS
            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}");
            }

            //GET SINGLE ROOM ENTRY
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");
            Room singleRoom = roomRepo.GetById(1);

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



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

            roomRepo.Insert(bathroom);

            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Room with id {bathroom.Id} named {bathroom.Name} that holds {bathroom.MaxOccupancy} people");


            //UPDATE object above"bathroom" on the property "maxoccupancy" and set it equal to "3"...
            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);
            //get it from database
            Room bathroomFromDB = roomRepo.GetById(bathroom.Id);

            //..then see it on the console
            Console.WriteLine($"{bathroomFromDB.Id} {bathroomFromDB.Name} {bathroomFromDB.MaxOccupancy}");


            //DELETE ROOM ENTRY BY ID
            roomRepo.Delete(bathroom.Id);
            //get all rooms and loop through them to show its deleted by delting the SQL assigned id of the entry
            allRooms = roomRepo.GetAll();
            foreach (Room room in allRooms)
            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }



            /*ROOMMATE TABLE QUERIES
             *************************************************************************************************8
             * ROOMMATE TABLE QUERIES */

            //creates new connection to roommate Repo
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Lastname}, {roommate.Firstname}");
            }


            //GET SINGLE Roommate ENTRY
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommate with Id 1");
            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname}, {singleRoommate.Lastname} paid {singleRoommate.RentPortion} in the {singleRoommate.Room.Name}");


            // GET ROOMmates BY roomId
            Console.WriteLine("Getting All Roommates");
            Console.WriteLine();

            List <Roommate> roommatesByRoomId = roommateRepo.GetRoommatesByRoomId(1);

            foreach (Roommate roommate in roommatesByRoomId)
            {
                Console.WriteLine($"omgz, {roommate.Id} {roommate.Lastname}, {roommate.Firstname}");
            }


            //ADD ENTRY
            //Created a new room to palce the new roommate,
            // OPTION 2: could fetch a room by using a .GetById method
            //Room singleRoom = roomRepo.GetById(1);
            //USED singleRoom that was declared above to be my object represntation that is passed through as an argument to my roommate as the room property
            Room myRoom = new Room
            {
                Name         = "YourRoom",
                MaxOccupancy = 2,
            };

            roomRepo.Insert(myRoom);
            Console.WriteLine($"Look {myRoom.Name} exists as a room");
            Roommate bestest = new Roommate
            {
                Firstname   = "Wife",
                Lastname    = "#1",
                RentPortion = 50,
                MoveInDate  = new DateTime(2011, 11, 11),
                //DateTime.Now.AddDays(-1);
                Room = singleRoom,
            };


            roommateRepo.Insert(bestest);

            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Roommate id number {bestest.Id} / name: {bestest.Firstname} {bestest.Lastname} / MoveIn: {bestest.MoveInDate} {bestest.Room.Name}");



            //UPDATE object above "bestest roommate" on the property "last name" and set it equal to "#2"...

            bestest.Lastname = "#2";
            roommateRepo.Update(bestest);
            //get it from database
            Roommate bestestFromDB = roommateRepo.GetById(bestest.Id);

            //..then see it on the console
            Console.WriteLine($"{bestestFromDB.Id} {bestestFromDB.Firstname} {bestestFromDB.Lastname}");


            // DELETE ROOMMATE ENTRY BY ID
            roommateRepo.Delete(bestest.Id);
            //get all roommatess and loop through them to show its deleted by delting the SQL assigned id of the entry
            allRoommates = roommateRepo.GetAll();
            foreach (Roommate roommates in allRoommates)
            {
                Console.WriteLine($"{roommates.Id} {roommates.Lastname} {roommates.Firstname}");
            }
        }
Beispiel #24
0
        static void Main(string[] args)
        {
            // <----- Rooms Test Code ----->

            /*RoomRepository roomRepo = new RoomRepository(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}");
             *
             * bathroom.MaxOccupancy = 2;
             *
             * roomRepo.Update(bathroom);
             *
             * Console.WriteLine("-------------------------------");
             *
             * allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             *
             * roomRepo.Delete(8);
             *
             * Console.WriteLine("-------------------------------");
             *
             * allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }*/

            // <----- Roommates Test Code ----->

            /*RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
             *
             * Console.WriteLine("Getting All Roommates:");
             * Console.WriteLine();
             *
             * List<Roommate> allRoommates = roommateRepo.GetAll();
             *
             * foreach (Roommate roommate in allRoommates)
             * {
             *  Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}");
             * }
             *
             * Console.WriteLine("----------------------------");
             * Console.WriteLine("Getting Roommate with Id 1");
             *
             * Roommate aRoommate = roommateRepo.GetById(1);
             *
             * Console.WriteLine($"{aRoommate.Id} {aRoommate.Firstname} {aRoommate.Lastname} {aRoommate.RentPortion} {aRoommate.MovedInDate} {aRoommate.Room}");
             *
             * Console.WriteLine("----------------------------");
             * Console.WriteLine("Getting Roommates with roomId 1");
             *
             * List<Roommate> allRoommatesWithRoomId = roommateRepo.GetRoommmatesByRoomId(1);
             *
             * foreach (Roommate roommate in allRoommatesWithRoomId)
             * {
             *  Console.WriteLine($"{roommate.Firstname} {roommate.Lastname} {roommate.Room.Name}");
             * }
             *
             * Roommate newRoommate = new Roommate
             * {
             *  Firstname = "Jimmy",
             *  Lastname = "Rocket",
             *  RentPortion = 2,
             *  MovedInDate = DateTime.Now,
             *  RoomId = 1
             * };
             *
             * roommateRepo.Insert(newRoommate);
             *
             * newRoommate.RentPortion = 10;
             *
             * roommateRepo.Update(newRoommate);
             *
             * roommateRepo.Delete(5);*/

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("Welcome to Roommates!");
            Console.WriteLine("Please select an option from the menu below:");
            Console.WriteLine("(1) View all roommates (2) View specific roommate by Id (3) Add a new roommate ");

            int userResponse = Int32.Parse(Console.ReadLine());

            switch (userResponse)
            {
            case 1:
                List <Roommate> listOfRoommates = roommateRepo.GetAll();
                foreach (Roommate roommate in listOfRoommates)
                {
                    Console.WriteLine($"Id: {roommate.Id} Name: {roommate.Firstname} {roommate.Lastname}");
                }
                ;
                break;

            case 2:
                Console.Write("Enter a roommate Id: ");
                int      res           = Int32.Parse(Console.ReadLine());
                Roommate foundRoommate = roommateRepo.GetById(res);
                Console.WriteLine($"Name: {foundRoommate.Firstname} {foundRoommate.Lastname} Moved In Date: {foundRoommate.MovedInDate}");
                break;

            case 3:
                Console.Write("Enter first name: ");
                string firstName = Console.ReadLine();
                Console.Write("Enter last name: ");
                string lastName = Console.ReadLine();
                Console.Write("Enter rent portion: ");
                int rentPortion = Int32.Parse(Console.ReadLine());
                Console.Write("Moved in date: ");
                DateTime movedInDate = DateTime.Parse(Console.ReadLine());
                Console.Write("Enter room id: ");
                int      roomId      = Int32.Parse(Console.ReadLine());
                Roommate newRoommate = new Roommate
                {
                    Firstname   = firstName,
                    Lastname    = lastName,
                    RentPortion = rentPortion,
                    MovedInDate = movedInDate,
                    RoomId      = roomId
                };
                roommateRepo.Insert(newRoommate);
                Console.WriteLine($"{firstName} {lastName} was successfully added!");
                break;
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(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}");
            }

            // >> Roommates
            Console.WriteLine("Getting All Rooms:");
            Console.WriteLine();
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.FirstName} {roommate.LastName} {roommate.RentPortion}");
            }

            // Getting Room with Id 1
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");
            Room singleRoom = roomRepo.GetById(1);

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


            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommate with Id 1");
            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.FirstName} {singleRoommate.LastName} {singleRoommate.RentPortion}");


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

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

            // INSERT ROOMATE
            // INSERT ROOMATE
            // INSERT ROOMATE
            string userTypedFirstName   = Console.ReadLine();
            string userTypedLastName    = Console.ReadLine();
            int    userTypedRentPortion = Int32.Parse(Console.ReadLine());

            // Roomsssssss...
            List <Room> someRooms = roomRepo.GetAll();
            Room        aRoom     = someRooms.First()
                                    // int userTypedRoomId = Int32.Parse(Console.ReadLine());
            ;
            Roommate newRoommate = new Roommate
            {
                FirstName   = userTypedFirstName,
                LastName    = userTypedLastName,
                RentPortion = userTypedRentPortion,
                MoveInDate  = DateTime.Now.AddDays(-1),
                Room        = aRoom
            };

            RoommateRepository.Insert(newRoommate);

            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Room with id {newRoommate.Id}");
            //Console.ReadLine($"First name: {userTypedFirstName}");

            // UPDATE
            new Room
            {
                Name         = "Bathroom2",
                MaxOccupancy = 2
            };
            roomRepo.Update(bathroom);
            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Room with id {bathroom.Id} 2");


            // DELETE
            roomRepo.Delete(10);
            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Deleted Room with id {bathroom.Id} 3");
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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}");
             *
             * bathroom.MaxOccupancy = 3;
             * roomRepo.Update(bathroom);
             *
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"Updated room to have a new occupancy of {bathroom.MaxOccupancy}");
             *
             * roomRepo.Delete(9);
             * roomRepo.Delete(8);
             *
             * allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }*/

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}");
            }

            Roommate roommateById = roommateRepo.GetById(1);

            Console.WriteLine();
            Console.WriteLine("Getting a roommate by Id");
            Console.WriteLine($"{roommateById.Id} {roommateById.Firstname} {roommateById.Lastname} {roommateById.RentPortion} {roommateById.MovedInDate}");

            List <Roommate> allRoommatesWithRooms = roommateRepo.GetAllWithRoom();

            Console.WriteLine();
            Console.WriteLine("Getting all roommates with rooms");

            foreach (Roommate roommateWithRoom in allRoommatesWithRooms)
            {
                Console.WriteLine($@"{roommateWithRoom.Id} {roommateWithRoom.Firstname} {roommateWithRoom.Lastname}
                                    {roommateWithRoom.RentPortion} {roommateWithRoom.MovedInDate} // 
                                    {roommateWithRoom.Room.Id} {roommateWithRoom.Room.Name} {roommateWithRoom.Room.MaxOccupancy}");
            }
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(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}");

            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);

            Room bathroomFromDb = roomRepo.GetById(bathroom.Id);

            Console.WriteLine($"{bathroomFromDb.Id} {bathroomFromDb.Name} {bathroomFromDb.MaxOccupancy}");
            Console.WriteLine("-------------------------------");
            roomRepo.Delete(bathroom.Id);

            allRooms = roomRepo.GetAll();

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

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}");
            }
            ;

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

            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} rent: {singleRoommate.RentPortion}%, date moved in: {singleRoommate.MovedInDate}");

            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting All Roommates with Room:");
            Console.WriteLine();

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

            foreach (Roommate roommate in allRoommatesWithRoom)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}");
            }
            ;

            Roommate newRoomate = new Roommate
            {
                Firstname   = "Lacey",
                Lastname    = "Walker",
                RentPortion = 15,
                MovedInDate = new DateTime(2020, 12, 07),
                Room        = allRooms[2]
            };

            roommateRepo.Insert(newRoomate);

            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Roommate with id {newRoomate.Id}");


            newRoomate.RentPortion = 20;
            roommateRepo.Update(newRoomate);
            allRoommates = roommateRepo.GetAll();
            Console.WriteLine("-----------------------------------------");
            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}");
            }

            roommateRepo.Delete(newRoomate.Id);
            allRoommates = roommateRepo.GetAll();
            Console.WriteLine("-----------------------------------------");
            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}");
            }
        }
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

            //returning list of rooms
            List <Room> allRooms = roomRepo.GetAll();

            //looping over room list and printing them all out
            foreach (Room room in allRooms)
            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }


            //calling getbyID method to print out the results
            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}");

            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);

            Room bathroomFromDb = roomRepo.GetById(bathroom.Id);

            Console.WriteLine($"{bathroomFromDb.Id} {bathroomFromDb.Name} {bathroomFromDb.MaxOccupancy}");
            Console.WriteLine("-------------------------------");

            roomRepo.Delete(bathroom.Id);

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

            ///////////Getting All Roommates w/o Room//////
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.FirstName} {roommate.LastName} {roommate.RentPortion} {roommate.MoveInDate}");
            }
            ///////////Getting One Single Roommate by Id //////

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

            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.FirstName} {singleRoommate.LastName} {singleRoommate.RentPortion} {singleRoommate.MoveInDate}");

            ///////////Getting All Rooms with Room Object Attatched //////
            RoommateRepository roommateRoomRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("Getting All Roommates with Room:");
            Console.WriteLine();

            List <Roommate> allRoommateswithRoom = roommateRoomRepo.GetAllWithRoom(2);

            foreach (Roommate roommateWithRoom in allRoommateswithRoom)
            {
                Console.WriteLine($"{roommateWithRoom.Id} {roommateWithRoom.FirstName} {roommateWithRoom.LastName} {roommateWithRoom.RentPortion} {roommateWithRoom.MoveInDate} {roommateWithRoom.Room.Name} {roommateWithRoom.Room.MaxOccupancy}");
            }


            ///////////Adding in New Roommate //////
            Roommate newRoommate = new Roommate
            {
                FirstName   = "Wendy",
                LastName    = "Jones",
                MoveInDate  = DateTime.Now.AddDays(-1),
                RoomId      = 1,
                RentPortion = 10
            };

            roommateRepo.Insert(newRoommate);


            ///////////Updating Roommate //////
            newRoommate.LastName = "Smith";

            roommateRepo.Update(newRoommate);

            allRoommates = roommateRepo.GetAll();
            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} First Name : {roommate.FirstName} Last Name: {roommate.LastName} Rent Portion: {roommate.RentPortion} Date Moved In : {roommate.MoveInDate}");
            }
            Console.WriteLine("-----------------------------------------");

            ///////////Deleting Roommate ///////////
            roommateRepo.Delete(newRoommate.Id);

            allRoommates = roommateRepo.GetAll();
            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} First Name : {roommate.FirstName} Last Name: {roommate.LastName} Rent Portion: {roommate.RentPortion} Date Moved In : {roommate.MoveInDate}");
            }
        }
Beispiel #29
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;
                }
            }
        }
Beispiel #30
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;
                }
            }
        }