private static void AddARoommate(RoomRepository roomRepo, RoommateRepository roommateRepo) { Console.Clear(); string message = "Enter your new roommate's first name"; string firstName = MooseSays(message); Console.Clear(); message = "Thanks! Now enter your new roommate's last name"; string lastName = MooseSays(message); Console.Clear(); message = "Sweet! What percentage of the rent will your roommate pay?"; int RentPortion; do { RentPortion = intMooseSays(message); } while (RentPortion < 1 || RentPortion > 100); Console.Clear(); if (RentPortion <= 10) { message = "Cheapskate, huh?"; } else if (RentPortion > 10 && RentPortion <= 70) { message = "Sounds reasonable."; } else if (RentPortion > 70) { message = "Hey moneybags!"; } message += " Which room do they get?"; int RoomId = intMooseSays(message); message = "Still wanna have them move in?"; Console.Clear(); string save = SaveMooseSays(message); if (save == "y") { Roommate newRoomate = new Roommate() { Firstname = firstName, Lastname = lastName, RentPortion = RentPortion, MoveInDate = DateTime.Now, RoomId = RoomId }; roommateRepo.Insert(newRoomate); Console.Clear(); RoommatePage(roomRepo, roommateRepo); } else { RoommatePage(roomRepo, roommateRepo); } }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); Console.WriteLine("-------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id}"); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } roomRepo.Delete(8); Console.WriteLine("Deleting"); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Room}"); Console.WriteLine(); // Console.WriteLine("Getting Roommate with specific Id"); // Roommate singleRoommate = roommateRepo.GetById(1); //Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname}"); } Roommate Aaron = new Roommate { Firstname = "Aaron" }; roommateRepo.Insert(Aaron); Console.WriteLine($"Added new roommate: {Aaron.Firstname}"); }
static void AddNewRoommate(RoomRepository roomRepo, RoommateRepository roommateRepo) { Roommate fred = new Roommate() { Firstname = "Friedrich", Lastname = "Franzferdinand", RentPortion = 25, MovedInDate = new DateTime(2020, 03, 04), Room = roomRepo.GetById(5) }; roommateRepo.Insert(fred); Console.WriteLine("\n-----------------------------"); Console.WriteLine($"Added new roommate with id {fred.Id}"); }
// method to add a roommate; private void Add() { DateTime respDate; int respPortion; //create new instance of Room that is set to the value of the user's choice from method ChooseRoom() below; Room newRoom; string rentPortion; string moveInDate; //create new instance of a roommate Roommate roommate = new Roommate(); do { Console.WriteLine("New Roommate"); Console.Write("First Name: "); roommate.Firstname = Console.ReadLine(); Console.Write("Last Name: "); roommate.Lastname = Console.ReadLine(); Console.Write("RentPortion: "); rentPortion = Console.ReadLine(); Console.Write("Move-in Date (MM/DD/YYY): "); moveInDate = Console.ReadLine(); newRoom = ChooseRoom(); }while (roommate.Firstname == "" || roommate.Lastname == "" || !Int32.TryParse(rentPortion, out respPortion) || !DateTime.TryParse(moveInDate, out respDate) || newRoom == null); roommate.RentPortion = respPortion; roommate.MoveInDate = respDate; //newRoom will hold the value of method from ChooseRoom() where user assigns room to the roommate; roommate.Room = newRoom; _roommateRepository.Insert(roommate); }
static void AddRoommate() { //Let's add a roommate Console.WriteLine("Let's add a roommate..."); RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Room frBedroom = roomRepo.GetById(1); //Add object for John Roommate roommate = new Roommate(); Console.WriteLine("Enter a first name for the roommate:"); roommate.FirstName = Console.ReadLine(); Console.WriteLine($"Enter a last name for {roommate.FirstName}:"); roommate.LastName = Console.ReadLine(); Console.WriteLine($"Enter the whole number rent portion for {roommate.FirstName} {roommate.LastName}:"); roommate.RentPortion = Int32.Parse(Console.ReadLine()); Console.WriteLine("Here is the list of room. Enter the room number for the roommate:"); GetRooms(); roommate.Room = GetRoom(Int32.Parse(Console.ReadLine())); roommate.MoveInDate = DateTime.Now.AddDays(1); //Tomorrow roommateRepo.Insert(roommate); Console.WriteLine($"Great! We've added {roommate.FirstName} to the list!"); ListAllRoommates(); }
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(); 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.MaxOccupancy = 3; roomRepo.Update(bathroom); Room bathroomFromDb = roomRepo.GetById(bathroom.Id); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); Console.WriteLine("-------------------------------"); roomRepo.Delete(bathroom.Id); allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } RoommateRepository roommateRepository = new RoommateRepository(CONNECTION_STRING); Roommate aRoommate = roommateRepository.GetById(2); Console.WriteLine($"{aRoommate.Firstname} {aRoommate.Lastname}"); /*Roommate another = roommateRepository.GetById(999); * Console.WriteLine($"{another.Firstname} {another.Lastname}");*/ Roommate newRoommate = new Roommate() { Firstname = "Sadie", Lastname = "Bean", MovedInDate = DateTime.Now.AddDays(-1), RoomId = 1, RentPortion = 10 }; roommateRepository.Insert(newRoommate); }
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}"); 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) { // <----- Rooms Test Code -----> /*RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); * * Console.WriteLine("Getting All Rooms:"); * Console.WriteLine(); * * List<Room> allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } * * Console.WriteLine("----------------------------"); * Console.WriteLine("Getting Room with Id 1"); * * Room singleRoom = roomRepo.GetById(1); * * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); * * Room bathroom = new Room * { * Name = "Bathroom", * MaxOccupancy = 1 * }; * * * roomRepo.Insert(bathroom); * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new Room with id {bathroom.Id}"); * * bathroom.MaxOccupancy = 2; * * roomRepo.Update(bathroom); * * Console.WriteLine("-------------------------------"); * * allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } * * roomRepo.Delete(8); * * Console.WriteLine("-------------------------------"); * * allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * }*/ // <----- Roommates Test Code -----> /*RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); * * Console.WriteLine("Getting All Roommates:"); * Console.WriteLine(); * * List<Roommate> allRoommates = roommateRepo.GetAll(); * * foreach (Roommate roommate in allRoommates) * { * Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}"); * } * * Console.WriteLine("----------------------------"); * Console.WriteLine("Getting Roommate with Id 1"); * * Roommate aRoommate = roommateRepo.GetById(1); * * Console.WriteLine($"{aRoommate.Id} {aRoommate.Firstname} {aRoommate.Lastname} {aRoommate.RentPortion} {aRoommate.MovedInDate} {aRoommate.Room}"); * * Console.WriteLine("----------------------------"); * Console.WriteLine("Getting Roommates with roomId 1"); * * List<Roommate> allRoommatesWithRoomId = roommateRepo.GetRoommmatesByRoomId(1); * * foreach (Roommate roommate in allRoommatesWithRoomId) * { * Console.WriteLine($"{roommate.Firstname} {roommate.Lastname} {roommate.Room.Name}"); * } * * Roommate newRoommate = new Roommate * { * Firstname = "Jimmy", * Lastname = "Rocket", * RentPortion = 2, * MovedInDate = DateTime.Now, * RoomId = 1 * }; * * roommateRepo.Insert(newRoommate); * * newRoommate.RentPortion = 10; * * roommateRepo.Update(newRoommate); * * roommateRepo.Delete(5);*/ RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Welcome to Roommates!"); Console.WriteLine("Please select an option from the menu below:"); Console.WriteLine("(1) View all roommates (2) View specific roommate by Id (3) Add a new roommate "); int userResponse = Int32.Parse(Console.ReadLine()); switch (userResponse) { case 1: List <Roommate> listOfRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in listOfRoommates) { Console.WriteLine($"Id: {roommate.Id} Name: {roommate.Firstname} {roommate.Lastname}"); } ; break; case 2: Console.Write("Enter a roommate Id: "); int res = Int32.Parse(Console.ReadLine()); Roommate foundRoommate = roommateRepo.GetById(res); Console.WriteLine($"Name: {foundRoommate.Firstname} {foundRoommate.Lastname} Moved In Date: {foundRoommate.MovedInDate}"); break; case 3: Console.Write("Enter first name: "); string firstName = Console.ReadLine(); Console.Write("Enter last name: "); string lastName = Console.ReadLine(); Console.Write("Enter rent portion: "); int rentPortion = Int32.Parse(Console.ReadLine()); Console.Write("Moved in date: "); DateTime movedInDate = DateTime.Parse(Console.ReadLine()); Console.Write("Enter room id: "); int roomId = Int32.Parse(Console.ReadLine()); Roommate newRoommate = new Roommate { Firstname = firstName, Lastname = lastName, RentPortion = rentPortion, MovedInDate = movedInDate, RoomId = roomId }; roommateRepo.Insert(newRoommate); Console.WriteLine($"{firstName} {lastName} was successfully added!"); break; } }
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(); 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); //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; } } }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } // >> Roommates Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.FirstName} {roommate.LastName} {roommate.RentPortion}"); } // Getting Room with Id 1 Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 1"); Room singleRoom = roomRepo.GetById(1); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 1"); Roommate singleRoommate = roommateRepo.GetById(1); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.FirstName} {singleRoommate.LastName} {singleRoommate.RentPortion}"); // INSERT ROOM Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id}"); // INSERT ROOMATE // INSERT ROOMATE // INSERT ROOMATE string userTypedFirstName = Console.ReadLine(); string userTypedLastName = Console.ReadLine(); int userTypedRentPortion = Int32.Parse(Console.ReadLine()); // Roomsssssss... List <Room> someRooms = roomRepo.GetAll(); Room aRoom = someRooms.First() // int userTypedRoomId = Int32.Parse(Console.ReadLine()); ; Roommate newRoommate = new Roommate { FirstName = userTypedFirstName, LastName = userTypedLastName, RentPortion = userTypedRentPortion, MoveInDate = DateTime.Now.AddDays(-1), Room = aRoom }; RoommateRepository.Insert(newRoommate); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {newRoommate.Id}"); //Console.ReadLine($"First name: {userTypedFirstName}"); // UPDATE new Room { Name = "Bathroom2", MaxOccupancy = 2 }; roomRepo.Update(bathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id} 2"); // DELETE roomRepo.Delete(10); Console.WriteLine("-------------------------------"); Console.WriteLine($"Deleted Room with id {bathroom.Id} 3"); }
static void Main(string[] args) { //Get All roommates //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}"); //} //Get roommates By Id //RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); //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}"); //Get roommate With All rooms //RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); //Console.WriteLine("----------------------------"); //Console.WriteLine("Getting Roommate with Rooms"); //List<Roommate> withRooms = roommateRepo.GetAllWithRoom(); //foreach (Roommate roommate in withRooms) //{ // Console.WriteLine($"{roommate.Id} {roommate.FirstName} {roommate.LastName} {roommate.RentPortion} {roommate.MoveInDate} {roommate.Room.Name} {roommate.Room.MaxOccupancy}"); //} //Create New roommate RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); List <Room> someRooms = roomRepo.GetAll(); Room aRoom = someRooms.First(); Roommate joe = new Roommate() { FirstName = "joe", LastName = "perry", RentPortion = 100, MoveInDate = DateTime.Now, Room = aRoom }; roommateRepo.Insert(joe); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Roommate with id {joe.Id} and name {joe.FirstName}: {joe.RentPortion} {joe.MoveInDate} {joe.Room.Name}"); //Get All rooms //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}"); //} //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} and name {bathroom.Name}: {bathroom.MaxOccupancy}"); //Update room //bathroom.Name = "Pooproom"; //bathroom.MaxOccupancy = 3; //roomRepo.Update(bathroom); //allRooms = roomRepo.GetAll(); //foreach (Room room in allRooms) //{ // Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); //} //Delete room ////roomRepo.Delete(17); ////roomRepo.Delete(18); ////roomRepo.Delete(19); ////roomRepo.Delete(20); }
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); 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 //}; }