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}"); //adding bathroom //Room bathroom = new Room //{ // Name = "Bathroom", // MaxOccupancy = 1 //}; //roomRepo.Insert(bathroom); //Room shed = new Room //{ // Name = "Shed", // MaxOccupancy = 50 //}; //roomRepo.Insert(shed); Console.WriteLine("-------------------------------"); //Console.WriteLine($"Added the new Room with id {shed.Id} and name of {shed.Name}"); //bathroom.MaxOccupancy = 18; //roomRepo.Update(bathroom); //Console.WriteLine($" bathrooms occupancy is {bathroom.Id}"); //roomRepo.Delete(9); //roomRepo.GetAll(); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); List <Roommate> withRoom = roommateRepo.GetAllWithRoom(3); foreach (Roommate rm in withRoom) { Console.WriteLine($"{rm.Firstname} is living in the {rm.Room.Name}"); } }
static void GetRoommatesInRoom(RoommateRepository roommateRepo) { // Get all roommates in the Living Room (room id of 3) Console.WriteLine("\nGetting All Roommates in the Living Room"); Console.WriteLine("------------------------------------------"); List <Roommate> roommatesInRoom = roommateRepo.GetAllWithRoom(3); foreach (Roommate roommate in roommatesInRoom) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room.Name}"); } }
static void RoommateReport(RoomRepository roomRepo, RoommateRepository roommateRepo) { // Display a report of all roommates and their rooms Console.WriteLine("\nReport -- All Roommates and their Rooms"); Console.WriteLine("======================================="); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { List <Roommate> roommatesInRoom = roommateRepo.GetAllWithRoom(room.Id); foreach (Roommate roommate in roommatesInRoom) { Console.WriteLine($"{roommate.Firstname} {roommate.Lastname}: {room.Name}"); } } }
static void Main(string[] args) { RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); Console.WriteLine("----------------------------"); Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } /* * Room bathroom = new Room * { * Name = "Bathroom", * MaxOccupancy = 1 * }; * * roomRepo.Insert(bathroom); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new Room with id {bathroom.Id}"); * * singleRoom.MaxOccupancy = 21; * roomRepo.Update(singleRoom); * * Console.WriteLine("----------------------------"); * Console.WriteLine($"{singleRoom.Name}'s occupancy has been changed to 21."); * * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); * * Roommate roommate1 = new Roommate * { * Firstname = "Michael", * Lastname = "Carroll", * RentPortion = 100, * MovedInDate = DateTime.Now, * Room = singleRoom * }; * * roommateRepo.Insert(roommate1); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new roommate {roommate1.Firstname} {roommate1.Lastname} with id {roommate1.Id} in the {roommate1.Room.Name} for {roommate1.RentPortion} to move in on {roommate1.MovedInDate}."); * * roomRepo.Delete(8); * * roommateRepo.Delete(5); * * singleRoommate.RentPortion = 75; * roommateRepo.Update(singleRoommate); * * Console.WriteLine("----------------------------"); * Console.WriteLine($"{singleRoommate.Firstname}'s rent portion has been changed to {singleRoommate.RentPortion}."); */ Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 5"); Room singleRoom = roomRepo.GetById(5); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 4"); Roommate singleRoommate = roommateRepo.GetById(4); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.RentPortion} {singleRoommate.MovedInDate} {singleRoommate.Room.Name}"); Console.WriteLine("----------------------------"); Console.WriteLine($"Getting all roommates in the room."); Console.WriteLine(); List <Roommate> allRoommatesWithRoom = roommateRepo.GetAllWithRoom(5); foreach (Roommate roommate in allRoommatesWithRoom) { Console.WriteLine(@$ " Name: {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}"); /* * Room updatedBathroom = new Room * { * Name = "Linen Closet", * MaxOccupancy = 1, * Id = bathroom.Id * }; * roomRepo.Update(updatedBathroom); * * allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } */ /* * roomRepo.Delete(17); * * allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } */ RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}"); } /* * Room singleRoommate = allRoommates.GetById(1); * * Console.WriteLine($"{singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.room.Name}"); */ List <Room> someRooms = roomRepo.GetAll(); Room aRoom = someRooms.First(); Roommate newRoommate = new Roommate() { Firstname = "Carrie", Lastname = "Wilson", RentPortion = 76, MovedInDate = DateTime.Now.AddDays(-1), Room = aRoom }; // roommateRepo.Insert(newRoommate); List <Roommate> roommates = roommateRepo.GetAllWithRoom(3); }
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); Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } /*Console.WriteLine("----------------------------"); * Console.WriteLine("Getting Room with Id 1"); * * Room singleRoom = roomRepo.GetById(1); * * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); * * Room bathroom = new Room * { * Name = "Bathroom", * MaxOccupancy = 1 * }; * * roomRepo.Insert(bathroom); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new Room with id {bathroom.Id}"); * * bathroom.MaxOccupancy = 3; * roomRepo.Update(bathroom); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Updated room to have a new occupancy of {bathroom.MaxOccupancy}"); * * roomRepo.Delete(9); * roomRepo.Delete(8); * * allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * }*/ RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine(); Console.WriteLine("-------------------------------"); Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}"); } Roommate roommateById = roommateRepo.GetById(1); Console.WriteLine(); Console.WriteLine("Getting a roommate by Id"); Console.WriteLine($"{roommateById.Id} {roommateById.Firstname} {roommateById.Lastname} {roommateById.RentPortion} {roommateById.MovedInDate}"); List <Roommate> allRoommatesWithRooms = roommateRepo.GetAllWithRoom(); Console.WriteLine(); Console.WriteLine("Getting all roommates with rooms"); foreach (Roommate roommateWithRoom in allRoommatesWithRooms) { Console.WriteLine($@"{roommateWithRoom.Id} {roommateWithRoom.Firstname} {roommateWithRoom.Lastname} {roommateWithRoom.RentPortion} {roommateWithRoom.MovedInDate} // {roommateWithRoom.Room.Id} {roommateWithRoom.Room.Name} {roommateWithRoom.Room.MaxOccupancy}"); } }
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("----------------------------"); 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("----------------------------"); //Console.WriteLine($"Updating Room with Id {bathroom.Id}"); //Room updatedBathroom = new Room //{ // Name = "Washroom", // MaxOccupancy = 1, // Id = bathroom.Id //}; //roomRepo.Update(updatedBathroom); allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } //roomRepo.Delete(8); //roomRepo.Delete(9); //roomRepo.Delete(10); //roomRepo.Delete(11); //roomRepo.Delete(12); //roomRepo.Delete(14); Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting Roommate with Id 1"); List <Roommate> someRoommates = roommateRepo.GetAllWithRoom(1); foreach (Roommate roommate in someRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room.Name}"); } Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------"); List <Room> someRooms = roomRepo.GetAll(); Room aRoom = someRooms.First(); Roommate newRoommate = new Roommate() { Firstname = "Carrie", Lastname = "Wilson", RentPortion = 76, MovedInDate = DateTime.Now.AddDays(-1), Room = aRoom }; roommateRepo.Insert(newRoommate); ////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("----------------------------"); ////Console.WriteLine($"Updating Room with Id {bathroom.Id}"); ////Room updatedBathroom = new Room ////{ //// Name = "Washroom", //// MaxOccupancy = 1, //// Id = bathroom.Id ////}; ////roomRepo.Update(updatedBathroom); //allRooms = roomRepo.GetAll(); //foreach (Room room in allRooms) //{ // Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); //} ////roomRepo.Delete(8); }
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.Delete(11); //roomRepo.Insert(bathroom); //Console.WriteLine("-------------------------------"); //Console.WriteLine($"Added the new Room with id {bathroom.Id}"); //Room updatedBathroom = new Room //{ // Id = 7, // Name = "Bathroom", // MaxOccupancy = 2 //}; //roomRepo.Update(updatedBathroom); //RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); //Console.WriteLine("Getting all roommates: "); //List<Roommate> roommates = roommateRepo.GetAll(); //foreach(Roommate rm in roommates) //{ // Console.WriteLine(@$" // Id: {rm.Id} // {rm.Firstname} {rm.Lastname} // Rent Portion: {rm.RentPortion} // Move In Date: {rm.MovedInDate} // "); //} //Roommate id1 = roommateRepo.GetById(1); //Console.WriteLine(@$" // {id1.Firstname} {id1.Lastname} // Rent Portion: {id1.RentPortion} // Move In Date: {id1.MovedInDate} // "); //List<Roommate> roommates = roommateRepo.GetAllWithRoom(); //foreach (Roommate rm in roommates) //{ // Console.WriteLine(@$" // Id: {rm.Id} // {rm.Firstname} {rm.Lastname} // Rent Portion: {rm.RentPortion} // Move In Date: {rm.MovedInDate} // Room: {rm.Room.Name} // "); //} RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); bool app = true; while (app == true) { int choice = -1; List <int> allRoomIds = roomRepo.GetAllIds(); List <int> allRoommateIds = roommateRepo.GetAllIds(); while (true) { Console.WriteLine(@" Welcome to Chore Manager! ------------------------- Select an option: 0 List all rooms 1 List room by Id 2 Add a room 3 Delete a room 4 Edit a room 5 List all roommates 6 List roommate by Id 7 Add a roommate 8 Edit a roommate 9 Delete a roommate "); string resp = Console.ReadLine(); if (resp == "") { app = false; break; } else { bool allowed = int.TryParse(resp, out choice); if (allowed && choice >= 0 && choice < 10) { break; } else { Console.WriteLine("Not a valid choice."); } } } switch (choice) { case 0: List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } break; case 1: int roomId = -1; while (true) { Console.WriteLine("Input Room Id: "); bool allowed = int.TryParse(Console.ReadLine(), out roomId); if (allowed && allRoomIds.Contains(roomId)) { break; } else { Console.WriteLine("Invalid Id. Choice is not an interger or Id does not exist."); } } Console.WriteLine($"Getting Room with Id {roomId}"); Room singleRoom = roomRepo.GetById(roomId); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); break; case 2: Console.WriteLine("Room name:"); string roomName = Console.ReadLine(); int maxOcc = -1; while (true) { Console.WriteLine("Maximum occupancy: "); bool allowed = int.TryParse(Console.ReadLine(), out maxOcc); if (allowed && maxOcc > 0) { break; } else { Console.WriteLine("Value must be a postive number"); } } Room newRoom = new Room { Name = roomName, MaxOccupancy = maxOcc }; roomRepo.Insert(newRoom); Console.WriteLine($"Added {newRoom.Name} with id {newRoom.Id}"); break; case 3: int roomToDelete = -1; while (true) { Console.WriteLine("Input Id of room to be deleted: "); string response = Console.ReadLine(); if (response == "") { break; } else { bool allowed = int.TryParse(response, out roomToDelete); if (allowed && allRoomIds.Contains(roomToDelete)) { break; } else { Console.WriteLine("Room does not exist. Please enter a valid room Id."); } } } if (roomToDelete == -1) { break; } else { roomRepo.Delete(roomToDelete); Console.WriteLine($"Deleted room with Id {roomToDelete}"); break; } case 4: int roomToEditId = -1; while (true) { Console.WriteLine("Enter Id of room to edit"); bool allowed = int.TryParse(Console.ReadLine(), out roomToEditId); if (allowed && allRoomIds.Contains(roomToEditId)) { Room roomToEdit = roomRepo.GetById(roomToEditId); Console.WriteLine($"{roomToEdit.Id} {roomToEdit.Name} {roomToEdit.MaxOccupancy}"); Console.WriteLine("Room name: "); string newName = Console.ReadLine(); if (newName == "") { newName = roomToEdit.Name; } int newOcc = -1; while (true) { Console.WriteLine("Max occupancy: "); bool permitted = int.TryParse(Console.ReadLine(), out newOcc); if (permitted && newOcc > 0) { break; } else { Console.WriteLine("Value must be a number > 0."); } } Room editedRoom = new Room { }; editedRoom.Id = roomToEditId; editedRoom.Name = newName; editedRoom.MaxOccupancy = newOcc; roomRepo.Update(editedRoom); Console.WriteLine($"Edited room: {editedRoom.Id} {editedRoom.Name} {editedRoom.MaxOccupancy}"); break; } else { Console.WriteLine("Room Id invalid. Please enter a valid Id."); } } break; case 5: List <Roommate> allRoommates = roommateRepo.GetAllWithRoom(); foreach (Roommate rm in allRoommates) { Console.WriteLine(@$ " Id: {rm.Id} {rm.Firstname} {rm.Lastname} Rent Portion: {rm.RentPortion} Move In Date: {rm.MovedInDate} "); } break; case 6: int roommateId = -1; while (true) { Console.WriteLine("Input Roommate Id: "); bool allowed = int.TryParse(Console.ReadLine(), out roommateId); if (allowed && allRoommateIds.Contains(roommateId)) { break; } else { Console.WriteLine("Invalid Id. Choice is not an interger or Id does not exist."); } } Console.WriteLine($"Getting Roommate with Id {roommateId}"); Roommate singleRoommate = roommateRepo.GetById(roommateId); Console.WriteLine(@$ " {singleRoommate.Firstname} {singleRoommate.Lastname} Rent Portion: {singleRoommate.RentPortion} Move In Date: {singleRoommate.MovedInDate}, Room: {singleRoommate.Room.Name} "); break;
static void Main(string[] args) { //RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); //Console.WriteLine("Getting All Rooms:"); //Console.WriteLine(); //List<Room> allRooms = roomRepo.GetAll(); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAllWithRoom(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"Roommate {roommate.Id} Information"); Console.WriteLine($"Full Name: {roommate.FirstName} {roommate.LastName}"); Console.WriteLine($"Rent Portion: {roommate.RentPortion}"); Console.WriteLine($"Date Moved In: {roommate.MoveInDate}"); Console.WriteLine($""); Console.WriteLine($"Roommates Room:"); Console.WriteLine($"Room Name: {roommate.Room.Name}"); Console.WriteLine($"Maximum Occupancy: {roommate.Room.MaxOccupancy}"); Console.WriteLine("---------------"); Console.WriteLine($""); } Roommate newRoommate = new Roommate { FirstName = "John", LastName = "Dough", RentPortion = 50, MoveInDate = DateTime.Now, Room = null }; roommateRepo.Insert(newRoommate); //RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); //Console.WriteLine("Getting All Rooms:"); //Console.WriteLine(); //List<Room> allRooms = roomRepo.GetAll(); //foreach (Room room in allRooms) //{ // Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); //} //Room frontBedroom = roomRepo.GetById(1); //Console.WriteLine("Enter a new name for the front room."); //frontBedroom.Name = Console.ReadLine(); //roomRepo.Update(frontBedroom); //roomRepo.Delete(2); //allRooms = roomRepo.GetAll(); //foreach (Room room in allRooms) //{ // Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); //} }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); /// Show the room with Id of 1. Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 1"); Room singleRoom = roomRepo.GetById(1); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); /// Create a new room known as Bathroom with a Max Occupancy of 1. Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); //Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id}"); Room updatedBathroom = new Room { Name = "Pool Room", MaxOccupancy = 40, Id = bathroom.Id }; roomRepo.Update(updatedBathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Deleting the new Room with id {bathroom.Id}"); roomRepo.Delete(bathroom.Id); 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("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} {roommate.Room}"); } Console.WriteLine($"Getting All Roommates with id 1:"); Console.WriteLine(); Roommate singleRoommate = roommateRepo.GetById(1); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.FirstName} {singleRoommate.RentPortion} {singleRoommate.MoveInDate} {singleRoommate.Room}"); Console.WriteLine($"Getting All Roommates with room Id of 1:"); Console.WriteLine(); List <Roommate> someRoommates = roommateRepo.GetAllWithRoom(1); foreach (Roommate roommate in someRoommates) { Console.WriteLine($"{roommate.FirstName} {roommate.LastName} {roommate.Room.Name}"); } }
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.Name = "Hotty Potty"; //bathroom.MaxOccupancy = 7; //roomRepo.Update(bathroom); //Room bath = roomRepo.GetById(8); //bath.Name = "Powder Room"; //bath.MaxOccupancy = 3; //roomRepo.Update(bath); //roomRepo.Delete(9); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); List <Roommate> allRoommates = roommateRepo.GetAll(); Console.WriteLine("-------------------------"); foreach (Roommate roommate in allRoommates) { Console.WriteLine(roommate.Firstname); Console.WriteLine(roommate.Lastname); Console.WriteLine(roommate.RentPortion); Console.WriteLine(roommate.MovedInDate); } Roommate singleRoommate = roommateRepo.GetById(2); Console.WriteLine($"Roommate Name is {singleRoommate.Firstname}"); List <Roommate> a = roommateRepo.GetAllWithRoom(3); foreach (Roommate roommate in a) { Console.WriteLine(roommate.Firstname); Console.WriteLine(roommate.Lastname); Console.WriteLine(roommate.RentPortion); Console.WriteLine(roommate.MovedInDate); Console.WriteLine(roommate.Room.Id); Console.WriteLine(roommate.Room.Name); Console.WriteLine(roommate.Room.MaxOccupancy); } }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); //Create //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 bathroomUpdate = roomRepo.GetById(7); //bathroomUpdate.MaxOccupancy = 2; //roomRepo.Update(bathroomUpdate); //Delete //roomRepo.Delete(8); 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}"); //ROOMMATE RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); //Roommate test = new Roommate() //{ // FirstName = "Chris", // LastName = "Test", // RentPortion = 100, // MoveInDate = DateTime.Now, // Room = singleRoom //}; //roommateRepo.Insert(test); Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 1"); Roommate singleRoommate = roommateRepo.GetById(1); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.FirstName} {singleRoommate.LastName} {singleRoommate.RentPortion} {singleRoommate.MoveInDate}"); singleRoommate.LastName = "Test3"; Console.WriteLine($"{singleRoommate.LastName} {singleRoommate.Room.Id}"); //roommateRepo.Update(singleRoommate); Console.WriteLine("----------------------------"); Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAllWithRoom(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.FirstName} {roommate.LastName} {roommate.RentPortion} {roommate.MoveInDate} {roommate.Room.Id} {roommate.Room.Name}"); } //roommateRepo.Delete(4); }
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(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 1"); Room singleRoom = roomRepo.GetById(1); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id}"); bathroom.MaxOccupancy = 3; roomRepo.Update(bathroom); Room bathroomFromDb = roomRepo.GetById(bathroom.Id); Console.WriteLine($"{bathroomFromDb.Id} {bathroomFromDb.Name} {bathroomFromDb.MaxOccupancy}"); Console.WriteLine("-------------------------------"); roomRepo.Delete(bathroom.Id); allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } Console.WriteLine("-------------------------------"); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}"); } ; Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 1"); Roommate singleRoommate = roommateRepo.GetById(1); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} rent: {singleRoommate.RentPortion}%, date moved in: {singleRoommate.MovedInDate}"); Console.WriteLine("----------------------------"); Console.WriteLine("Getting All Roommates with Room:"); Console.WriteLine(); List <Roommate> allRoommatesWithRoom = roommateRepo.GetAllWithRoom(1); foreach (Roommate roommate in allRoommatesWithRoom) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}"); } ; Roommate newRoomate = new Roommate { Firstname = "Lacey", Lastname = "Walker", RentPortion = 15, MovedInDate = new DateTime(2020, 12, 07), Room = allRooms[2] }; roommateRepo.Insert(newRoomate); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Roommate with id {newRoomate.Id}"); newRoomate.RentPortion = 20; roommateRepo.Update(newRoomate); allRoommates = roommateRepo.GetAll(); Console.WriteLine("-----------------------------------------"); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}"); } roommateRepo.Delete(newRoomate.Id); allRoommates = roommateRepo.GetAll(); Console.WriteLine("-----------------------------------------"); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} rent: {roommate.RentPortion}%, date moved in: {roommate.MovedInDate}"); } }
static void Main(string[] args) { //Selects all Rooms and displays them to the console 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 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}"); } Console.WriteLine("-------------------------------"); ///////////////////////////////////////// /* Gets a single Room via Id * Console.WriteLine("----------------------------"); * Console.WriteLine("Getting Room with Id 1"); * * Room singleRoom = roomRepo.GetById(1); * * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); */ Console.WriteLine("Getting Roommate with Id 2"); Roommate singleRoommate = roommateRepo.GetById(2); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.RentPortion} {singleRoommate.MoveInDate}"); Console.WriteLine("-------------------------------"); Console.WriteLine("Getting Roommates within a Specific Room"); List <Roommate> roommatesWithRoom = roommateRepo.GetAllWithRoom(3); foreach (Roommate roommate in roommatesWithRoom) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} lives in the {roommate.Room.Name}, pays ${roommate.RentPortion}, and moved in on {roommate.MoveInDate}"); } Console.WriteLine("-------------------------------"); ///////////////////////////////////////// /* Generates a new room and adds it to the database * Room bathroom = new Room * { * Name = "Bathroom", * MaxOccupancy = 1 * }; * * roomRepo.Insert(bathroom); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new Room {bathroom.Name} with id {bathroom.Id}"); */ /* * Roommate Kevin = new Roommate * { * Firstname = "Kevin", * Lastname = "Schmidt", * RentPortion = 75, * MoveInDate = new DateTime(2015, 12, 31), * Room = allRooms[1] * }; * * roommateRepo.Insert(Kevin); * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added a new roommate, please welcome {Kevin.Id} {Kevin.Firstname} {Kevin.Lastname}"); */ ///////////////////////////////////////// /* Updates an entry in the database * bathroom.MaxOccupancy = 3; * * roomRepo.Update(bathroom); * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } */ /* * Kevin.RentPortion = 500; * roommateRepo.Update(Kevin); * Console.WriteLine($"{Kevin.Firstname}'s new rent payment is ${Kevin.RentPortion}"); * Console.WriteLine("-------------------------------"); */ ///////////////////////////////////////// /* Deletes a room entry from the database * * Console.WriteLine("-------------------------------"); * Console.WriteLine("Deleting bathrooms"); * roomRepo.Delete(12); * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * }*/ }