Beispiel #1
0
        static void EditRoommate(RoommateRepository roommateRepo)
        {
            Roommate roommateToEdit = roommateRepo.GetById(3);

            roommateToEdit.RentPortion = 20;

            roommateRepo.Update(roommateToEdit);
            Console.WriteLine($"{roommateToEdit.Firstname} {roommateToEdit.Lastname} has been updated!");
        }
Beispiel #2
0
        static void UpdateRoommate()
        {
            // Update Roommate
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("------------------ Roommate List -------------------");
            ListAllRoommates();
            Console.WriteLine("----------- Enter the Id of the Roommate You'd Like to Edit  -------------");
            Roommate roommate   = roommateRepo.GetById(Int32.Parse(Console.ReadLine()));
            string   rmResponse = null;

            Console.WriteLine("Enter a new first name for the roommate or press ENTER");
            rmResponse = Console.ReadLine();
            if (rmResponse != "")
            {
                roommate.FirstName = rmResponse;
            }
            Console.WriteLine("Enter a new last name for the roommate or press ENTER");
            rmResponse = Console.ReadLine();
            if (rmResponse != "")
            {
                roommate.LastName = rmResponse;
            }
            Console.WriteLine("Enter a whole number rent portion for this roommate or press ENTER");
            rmResponse = Console.ReadLine();
            if (rmResponse != "")
            {
                roommate.RentPortion = Int32.Parse(rmResponse);
            }
            Console.WriteLine("Enter a new move in date for the roommate MM-DD-YY or press ENTER: ");
            rmResponse = Console.ReadLine();
            if (rmResponse != "")
            {
                roommate.MoveInDate = DateTime.Parse(rmResponse);
            }
            Console.WriteLine("Enter the Room ID for the roommate or press ENTER: ");
            GetRooms();
            rmResponse = Console.ReadLine();
            if (rmResponse != "")
            {
                roommate.Room = GetRoom(Int32.Parse(rmResponse));
            }
            roommateRepo.Update(roommate);
            roommate = roommateRepo.GetById(roommate.Id);
            Console.WriteLine("Here is the Updated Roommate:");
            Console.WriteLine("First Name \t Last name \t Rent Portion \t Move In Date \t Room Name \t Max Occupancy");
            Console.WriteLine($"{roommate.Id} {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);
        }
Beispiel #4
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 #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}");
            }

            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}");
            }
        }
Beispiel #6
0
        private void Edit()
        {
            Roommate roommateToEdit = ChooseRoommate("Which roommate would you like to edit?");

            if (roommateToEdit == null)
            {
                return;
            }

            Console.WriteLine();
            Console.Write("New first name (blank to leave unchanged): ");
            string firstName = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(firstName))
            {
                roommateToEdit.Firstname = firstName;
            }
            Console.Write("New last name (blank to leave unchanged): ");
            string lastName = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(lastName))
            {
                roommateToEdit.Lastname = lastName;
            }
            Console.Write("New Rent Portion (blank to leave unchanged): ");
            string rentPortion = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(rentPortion))
            {
                try
                {
                    roommateToEdit.RentPortion = int.Parse(rentPortion);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid Input. Please Try Again.");
                    Execute();
                }
            }
            Console.Write("New Move In Date MM-DD-YYYY (blank to leave unchanged): ");
            string moveInDate = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(moveInDate))
            {
                try
                {
                    roommateToEdit.MoveInDate = DateTime.Parse(moveInDate);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid Date Input. Please Try Again.");
                    Execute();
                }
            }

            //get all room in list
            Console.Write("Choose a New Room: ");

            List <Room> rooms = _roomRepository.GetAll();


            //iterate through the the rooms list and display each room's name and index +1;
            for (int i = 0; i < rooms.Count; i++)
            {
                Room room = rooms[i];
                Console.WriteLine($"{i + 1} {room.Name}");
            }
            Console.WriteLine(">");
            //read the user's choice for the room;
            string userRoomChoice = Console.ReadLine();



            //if user does not choose anything, then the current room will stay the same;
            if (!string.IsNullOrWhiteSpace(userRoomChoice))
            {
                //will catch
                try
                {
                    int userRoomChoiceIndex = int.Parse(userRoomChoice);
                    roommateToEdit.Room = rooms[userRoomChoiceIndex - 1];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid Room Choice. Please Try Again.");
                    Execute();
                }
            }
            else
            {
                Console.WriteLine("Please choose a valid Room Choice.");
                Execute();
            }

            _roommateRepository.Update(roommateToEdit);
        }
Beispiel #7
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 #8
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 #9
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");
                }
            }
        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 #11
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 #12
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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


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

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

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

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



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

            while (true)
            {
                Console.WriteLine();

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

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

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

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


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

                    roomRepo.Insert(AddedRoom);

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

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

                    roomRepo.Delete(roomId);

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

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

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

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

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

                    roomRepo.Update(UpdatedRoom);

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

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

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

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

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


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

                    roommateRepo.Insert(AddedRoommate);

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

                case 7:     //Edit a roommate's info

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

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

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

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

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

                    DateTime EditMoveInDate = DateTime.Now;

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

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

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

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

                    roommateRepo.Update(UpdatedRoommate);

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

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

                    roomRepo.Delete(roommateId);

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

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

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

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

            Console.WriteLine(@"
Welcome, what would you like to do today? 
1: View or edit rooms
2: View or edit roommates
");
            int response = int.Parse(Console.ReadLine());

            switch (response)
            {
            case 1:
                Console.WriteLine(@"
                    What would you like to do?
                    1: View all rooms
                    2: View individual room info
                    3: Add a room
                    4: Edit room info
                    5: Delete a room");
                int roomResponse = int.Parse(Console.ReadLine());
                switch (roomResponse)
                {
                case 1:
                    Console.WriteLine("Getting All Rooms:");
                    Console.WriteLine();

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

                    foreach (Room room in allRoommates)
                    {
                        Console.WriteLine($"{room.Name} has an Id of {room.Id} and a max occupancy of {room.MaxOccupancy}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter a room number:");
                    int  roomNum    = int.Parse(Console.ReadLine());
                    Room singleRoom = roomRepo.GetById(roomNum);
                    Console.WriteLine($"{singleRoom.Name}, Max occupancy: {singleRoom.MaxOccupancy}");
                    break;

                case 3:
                    Console.WriteLine("Enter room name:");
                    string newRoomName = Console.ReadLine();
                    Console.WriteLine($"Enter {newRoomName}'s max occupancy:");
                    int  newRoomOccupancy = int.Parse(Console.ReadLine());
                    Room newRoom          = new Room()
                    {
                        Name         = newRoomName,
                        MaxOccupancy = newRoomOccupancy
                    };
                    roomRepo.Insert(newRoom);
                    Console.WriteLine($"Added {newRoomName}.");
                    break;

                case 4:
                    Console.WriteLine("Enter a room number:");
                    int editNum = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter the room's name:");
                    string newName = Console.ReadLine();
                    Console.WriteLine("Enter the room's max occupancy:");
                    int  newOcc      = int.Parse(Console.ReadLine());
                    Room edittedRoom = new Room()
                    {
                        Name         = newName,
                        MaxOccupancy = newOcc,
                        Id           = editNum
                    };
                    roomRepo.Update(edittedRoom);
                    Console.WriteLine($"Updated {newName} info");
                    break;

                case 5:
                    Console.WriteLine("Enter a room number:");
                    roomRepo.Delete(int.Parse(Console.ReadLine()));
                    Console.WriteLine("Deleted");
                    break;
                }
                break;

            case 2:
                Console.WriteLine(@"
                    What would you like to do?
                    1: View all roommates
                    2: View individual roommate info
                    3: Add a roommate
                    4: Edit roommate info
                    5: Delete a roommate
                    6: View all roommates in specific room");
                int roommateResponse = int.Parse(Console.ReadLine());
                switch (roommateResponse)
                {
                case 1:
                    Console.WriteLine("Getting All Roommates:");
                    Console.WriteLine();

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

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine($@"
                                {roommate.Firstname}{roommate.Lastname}
                                ID: {roommate.Id} 
                                Rent portion: {roommate.RentPortion}
                                Move in date: {roommate.MovedInDate}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter a roommate number:");
                    int      roommateNum    = int.Parse(Console.ReadLine());
                    Roommate singleRoommate = roommateRepo.GetById(roommateNum);
                    Console.WriteLine($@"
                                {singleRoommate.Firstname}{singleRoommate.Lastname}
                                ID: {singleRoommate.Id} 
                                Rent portion: {singleRoommate.RentPortion}
                                Move in date: {singleRoommate.MovedInDate}");
                    break;

                case 3:
                    Console.WriteLine("Enter roommate's first name:");
                    string newRoommateFirstName = Console.ReadLine();
                    Console.WriteLine($"Enter {newRoommateFirstName}'s last name:");
                    string newRoommateLastName = Console.ReadLine();
                    Console.WriteLine($"Enter {newRoommateFirstName}'s rent portion:");
                    int newRoommateRent = int.Parse(Console.ReadLine());
                    Console.WriteLine($"When did they move in?");
                    DateTime newRoommateMove = DateTime.Parse(Console.ReadLine());
                    Console.WriteLine("Enter room ID:");
                    int  newRoommateRoomId = int.Parse(Console.ReadLine());
                    Room newRoommateRoom   = roomRepo.GetById(newRoommateRoomId);

                    Roommate newRoommate = new Roommate()
                    {
                        Firstname   = newRoommateFirstName,
                        Lastname    = newRoommateLastName,
                        RentPortion = newRoommateRent,
                        MovedInDate = newRoommateMove,
                        Room        = newRoommateRoom
                    };
                    roommateRepo.Insert(newRoommate);
                    Console.WriteLine($"Added {newRoommateFirstName}.");
                    break;

                case 4:
                    Console.WriteLine("Enter roommate ID:");
                    int editRoommateId = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter roommate's first name:");
                    string editRoommateFirstName = Console.ReadLine();
                    Console.WriteLine($"Enter {editRoommateFirstName}'s last name:");
                    string editRoommateLastName = Console.ReadLine();
                    Console.WriteLine($"Enter {editRoommateFirstName}'s rent portion:");
                    int editRoommateRent = int.Parse(Console.ReadLine());
                    Console.WriteLine($"When did they move in?");
                    DateTime editRoommateMove = DateTime.Parse(Console.ReadLine());
                    Console.WriteLine("Enter room ID:");
                    int  editRoommateRoomId = int.Parse(Console.ReadLine());
                    Room editRoommateRoom   = roomRepo.GetById(editRoommateRoomId);

                    Roommate editRoommate = new Roommate()
                    {
                        Id          = editRoommateId,
                        Firstname   = editRoommateFirstName,
                        Lastname    = editRoommateLastName,
                        RentPortion = editRoommateRent,
                        MovedInDate = editRoommateMove,
                        Room        = editRoommateRoom
                    };
                    roommateRepo.Update(editRoommate);
                    Console.WriteLine($"Updated {editRoommateFirstName}'s info.");
                    break;

                case 5:
                    Console.WriteLine("Enter a roommate ID:");
                    roommateRepo.Delete(int.Parse(Console.ReadLine()));
                    Console.WriteLine("Deleted");
                    break;

                case 6:
                    Console.WriteLine("Enter the room's ID:");
                    int             singleRoomId = int.Parse(Console.ReadLine());
                    List <Roommate> roomMembers  = roommateRepo.GetRoommatesByRoomId(singleRoomId);
                    foreach (Roommate roommate in roomMembers)
                    {
                        Console.WriteLine($@"
                                {roommate.Firstname}{roommate.Lastname}
                                ID: {roommate.Id} 
                                Rent portion: {roommate.RentPortion}
                                Move in date: {roommate.MovedInDate}");
                    }

                    ;
                    break;
                }
                break;
                ;
            }



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

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


            //}
            //break;



            //Roommate newRoommate = new Roommate()
            //{
            //    Firstname = "Wes",
            //    Lastname = "Harrison",
            //    RentPortion = 20,
            //    MovedInDate = DateTime.Parse("1/1/2021"),
            //    Room = backBedroom
            //};
            //roommateRepo.Insert(newRoommate);

            //Roommate updatedRoommate = new Roommate()
            //{
            //    Firstname = "Wes",
            //    Lastname = "Harrison",
            //    RentPortion = 30,
            //    MovedInDate = DateTime.Parse("1/1/2021"),
            //    Room = backBedroom,
            //    Id = 4
            //};
        }