private void Remove() { Roommate roommateToDelete = ChooseRoommate("Which Roommate would you like to remove?"); if (roommateToDelete != null) { _roommateRepository.Delete(roommateToDelete.Id); } }
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); }
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}"); } }
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}"); } }
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 DeleteRoommate(RoommateRepository roommateRepo) { roommateRepo.Delete(5); Console.Clear(); Console.WriteLine($"Roommate has been removed."); }
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}"); } }
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(""); } } }
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}"); } }
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); */ }
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 //}; }