static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); //GET ALL ROOMS Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } //GET SINGLE ROOM ENTRY Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 1"); Room singleRoom = roomRepo.GetById(1); Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); //ADD ROOM ENTRY Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id} named {bathroom.Name} that holds {bathroom.MaxOccupancy} people"); //UPDATE object above"bathroom" on the property "maxoccupancy" and set it equal to "3"... bathroom.MaxOccupancy = 3; roomRepo.Update(bathroom); //get it from database Room bathroomFromDB = roomRepo.GetById(bathroom.Id); //..then see it on the console Console.WriteLine($"{bathroomFromDB.Id} {bathroomFromDB.Name} {bathroomFromDB.MaxOccupancy}"); //DELETE ROOM ENTRY BY ID roomRepo.Delete(bathroom.Id); //get all rooms and loop through them to show its deleted by delting the SQL assigned id of the entry allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); } /*ROOMMATE TABLE QUERIES *************************************************************************************************8 * ROOMMATE TABLE QUERIES */ //creates new connection to roommate Repo RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); // GET ALL ROOMMATES Console.WriteLine("Getting All Roommates:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Lastname}, {roommate.Firstname}"); } //GET SINGLE Roommate ENTRY Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 1"); Roommate singleRoommate = roommateRepo.GetById(1); Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname}, {singleRoommate.Lastname} paid {singleRoommate.RentPortion} in the {singleRoommate.Room.Name}"); // GET ROOMmates BY roomId Console.WriteLine("Getting All Roommates"); Console.WriteLine(); List <Roommate> roommatesByRoomId = roommateRepo.GetRoommatesByRoomId(1); foreach (Roommate roommate in roommatesByRoomId) { Console.WriteLine($"omgz, {roommate.Id} {roommate.Lastname}, {roommate.Firstname}"); } //ADD ENTRY //Created a new room to palce the new roommate, // OPTION 2: could fetch a room by using a .GetById method //Room singleRoom = roomRepo.GetById(1); //USED singleRoom that was declared above to be my object represntation that is passed through as an argument to my roommate as the room property Room myRoom = new Room { Name = "YourRoom", MaxOccupancy = 2, }; roomRepo.Insert(myRoom); Console.WriteLine($"Look {myRoom.Name} exists as a room"); Roommate bestest = new Roommate { Firstname = "Wife", Lastname = "#1", RentPortion = 50, MoveInDate = new DateTime(2011, 11, 11), //DateTime.Now.AddDays(-1); Room = singleRoom, }; roommateRepo.Insert(bestest); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Roommate id number {bestest.Id} / name: {bestest.Firstname} {bestest.Lastname} / MoveIn: {bestest.MoveInDate} {bestest.Room.Name}"); //UPDATE object above "bestest roommate" on the property "last name" and set it equal to "#2"... bestest.Lastname = "#2"; roommateRepo.Update(bestest); //get it from database Roommate bestestFromDB = roommateRepo.GetById(bestest.Id); //..then see it on the console Console.WriteLine($"{bestestFromDB.Id} {bestestFromDB.Firstname} {bestestFromDB.Lastname}"); // DELETE ROOMMATE ENTRY BY ID roommateRepo.Delete(bestest.Id); //get all roommatess and loop through them to show its deleted by delting the SQL assigned id of the entry allRoommates = roommateRepo.GetAll(); foreach (Roommate roommates in allRoommates) { Console.WriteLine($"{roommates.Id} {roommates.Lastname} {roommates.Firstname}"); } }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); /* * Console.WriteLine("Getting All Rooms:"); * Console.WriteLine(); * * List<Room> allRooms = roomRepo.GetAll(); * * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } */ Console.WriteLine("----------------------------"); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("getting all the roommates"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetAll(); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}"); } /* * Console.WriteLine("----------------------------"); * * Console.WriteLine("Getting Room with Id 1"); * * Room singleRoom = roomRepo.GetById(1); * * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}"); */ Console.WriteLine("----------------------------"); Console.WriteLine("Getting Roommate with Id 1"); Roommate roommate1 = roommateRepo.GetById(1); Console.WriteLine($"{roommate1.Firstname} {roommate1.Lastname} {roommate1.Room}"); Console.WriteLine("----------------------------"); // getting roommates based on roomId Console.WriteLine("getting all the roommates and all their room info"); List <Roommate> allRoommatesWithRoom = roommateRepo.GetRoommatesByRoomId(1); foreach (Roommate roommateWithRoom in allRoommatesWithRoom) { Console.WriteLine($"{roommateWithRoom.Id}: {roommateWithRoom.Firstname} {roommateWithRoom.Lastname} is assigned {roommateWithRoom.Room.Name}; \n pays {roommateWithRoom.RentPortion} move-in-date: {roommateWithRoom.MovedInDate}"); } ; Console.WriteLine("----------------------------"); Roommate newRoommate = new Roommate { Firstname = "pablo", Lastname = "nuts", MovedInDate = new DateTime(2020, 2, 22), RentPortion = 12, Room = roomRepo.GetById(1) }; //roommateRepo.Insert(newRoommate); //update roommateRepo.Update(newRoommate); Console.WriteLine($"updated juan to {newRoommate.Firstname}"); Console.WriteLine("----------------------------"); roommateRepo.Delete(2); /* * Room bathroom = new Room * { * Name = "Bathroom", * MaxOccupancy = 1 * }; * * roomRepo.Insert(bathroom); * */ /* * Console.WriteLine("-------------------------------"); * Console.WriteLine($"Added the new Room with id {bathroom.Id}"); * * bathroom.MaxOccupancy = 3; * * roomRepo.Update(bathroom); * * * Console.WriteLine("-------------------------------"); * Console.WriteLine($"updated the room to have max occupancy of {bathroom.MaxOccupancy}"); */ /* * foreach (Room room in allRooms) * { * Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}"); * } * Console.WriteLine("-------------------------------"); * * roomRepo.Delete(bathroom.Id); */ }
static void Main(string[] args) { RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING); Console.WriteLine("Getting All Rooms:"); Console.WriteLine(); List <Room> allRooms = roomRepo.GetAll(); foreach (Room room in allRooms) { Console.WriteLine($"{room.Name} has an Id of {room.Id} and a max occupancy of {room.MaxOccupancy}"); } Console.WriteLine("----------------------------"); Console.WriteLine("Getting Room with Id 1"); Room singleRoom = roomRepo.GetById(1); Console.WriteLine($"Single room ID: {singleRoom.Id} Single room name: {singleRoom.Name} Single room occupancy: {singleRoom.MaxOccupancy}"); Room bathroom = new Room { Name = "Bathroom", MaxOccupancy = 1 }; roomRepo.Insert(bathroom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Added the new Room with id {bathroom.Id}"); Room updatedRoom = new Room { Name = "Front Room", MaxOccupancy = 5, Id = 1 }; roomRepo.Update(updatedRoom); Console.WriteLine("-------------------------------"); Console.WriteLine($"Updated front room, occupancy is now: {updatedRoom.MaxOccupancy}"); roomRepo.Delete(2); Console.WriteLine("-------------------------------"); Console.WriteLine($"Deleted back bedroom"); RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING); Console.WriteLine("Getting Roommates by Room Id:"); Console.WriteLine(); List <Roommate> allRoommates = roommateRepo.GetRoommatesByRoomId(1); foreach (Roommate roommate in allRoommates) { Console.WriteLine($"{roommate.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 //}; }