Esempio n. 1
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

            foreach (Room room in allRooms)
            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");

            Room singleRoom = roomRepo.GetById(1);

            Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            //Room bathroom = new Room
            //{
            //    Name = "Bathroom",
            //    MaxOccupancy = 1
            //};

            //roomRepo.Insert(bathroom);

            //Console.WriteLine("-------------------------------");
            //Console.WriteLine($"Added the new Room with id {bathroom.Id}");

            //bathroom.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);
            }
        }
Esempio n. 2
0
        public List <Roommate> GetAll()
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT roommate.Id AS 'roomyId', FirstName, LastName, MoveInDate, RentPortion, room.Id AS 'roomId', room.Name AS 'roomName', room.MaxOccupancy AS 'roomOcc' 
                    FROM Roommate roommate JOIN Room room ON room.Id = Roommate.RoomId";

                    SqlDataReader reader = cmd.ExecuteReader();

                    List <Roommate> roommates = new List <Roommate>();

                    while (reader.Read())
                    {
                        int idColumnPosition = reader.GetOrdinal("roomyId");
                        int idValue          = reader.GetInt32(idColumnPosition);

                        int    firstNameColumnPosition = reader.GetOrdinal("FirstName");
                        string firstNameValue          = reader.GetString(firstNameColumnPosition);

                        int    lastNameColumnPosition = reader.GetOrdinal("LastName");
                        string lastNameValue          = reader.GetString(lastNameColumnPosition);

                        int rentPortionColumnPosition = reader.GetOrdinal("RentPortion");
                        int rentPortion = reader.GetInt32(rentPortionColumnPosition);

                        int      moveInDateColumnPosition = reader.GetOrdinal("MoveInDate");
                        DateTime moveInDate = reader.GetDateTime(moveInDateColumnPosition);

                        int roomIdColumnPosition = reader.GetOrdinal("roomId");
                        int roomIdValue          = reader.GetInt32(roomIdColumnPosition);


                        int    roomNameColumnPosition = reader.GetOrdinal("roomName");
                        string roomName = reader.GetString(roomNameColumnPosition);

                        int roomOcc      = reader.GetOrdinal("roomOcc");
                        int roomOccValue = reader.GetInt32(roomOcc);

                        Roommate roommate = new Roommate
                        {
                            Id          = idValue,
                            Firstname   = firstNameValue,
                            Lastname    = lastNameValue,
                            RentPortion = rentPortion,
                            MovedInDate = moveInDate,
                            Room        = new Room
                            {
                                Id           = roomIdValue,
                                Name         = roomName,
                                MaxOccupancy = roomOccValue
                            }
                        };

                        // ...and add that room object to our list.
                        roommates.Add(roommate);
                    }

                    // We should Close() the reader. Unfortunately, a "using" block won't work here.
                    reader.Close();

                    // Return the list of rooms who whomever called this method.
                    return(roommates);
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // ROOM CALLS
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            // GET ROOM BY ID
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");
            Room singleRoom = roomRepo.GetById(1);

            Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            // CREATE NEW ROOM
            Room bathroom = new Room
            {
                Name         = "Bathroom",
                MaxOccupancy = 1
            };

            roomRepo.Insert(bathroom);
            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Room with id {bathroom.Id}");

            // UPDATE ROOM
            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);
            Room bathroomFromDb = roomRepo.GetById(bathroom.Id);

            Console.WriteLine($"{bathroomFromDb.Id} {bathroomFromDb.Name} {bathroomFromDb.MaxOccupancy}");

            //DELETE ROOM
            Console.WriteLine("-------------------------------");
            roomRepo.Delete(bathroom.Id);
            allRooms = roomRepo.GetAll();
            foreach (Room room in allRooms)
            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }


            // ROOMMATE CALLS
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

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

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName} moved in on {roommate.MoveInDate} and pays {roommate.RentPortion} per month");
            }

            // GET ROOMMATE BY ID
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommate with Id 1");
            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id}. {singleRoommate.FirstName} {singleRoommate.LastName}");

            // GET ROOMMATE WITH ROOM
            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommates with Room");
            List <Roommate> roommatesRooms = roommateRepo.GetAllWithRoom(5);

            foreach (Roommate roommate in roommatesRooms)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName} lives in room {roommate.Room.Id}");
            }

            // CREATE NEW ROOMMATE
            Roommate rick = new Roommate
            {
                FirstName   = "Big",
                LastName    = "Rick",
                RentPortion = 10,
                MoveInDate  = DateTime.Now,
                Room        = roomRepo.GetById(4)
            };

            roommateRepo.Insert(rick);
            Console.WriteLine("-------------------------------");
            Console.WriteLine($"Added the new Roommate with id {rick.Id}");

            // UPDATE ROOMMATE
            rick.LastName = "Ricky";
            roommateRepo.Update(rick);

            Roommate rickFromDb = roommateRepo.GetById(rick.Id);

            Console.WriteLine($"{rickFromDb.Id}. {rickFromDb.FirstName} {rickFromDb.LastName}");

            //DELETE ROOMMATE
            Console.WriteLine("-------------------------------");
            roommateRepo.Delete(4);

            allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id}. {roommate.FirstName} {roommate.LastName}");
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);
                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for chore"):
                    Console.WriteLine("Chore Id: ");
                    int   choreId = int.Parse(Console.ReadLine());
                    Chore chore   = choreRepo.GetById(choreId);
                    Console.WriteLine($"{chore.Id} - {chore.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.WriteLine("Chore name: ");
                    string choreName  = Console.ReadLine();
                    Chore  choreToAdd = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(choreToAdd);
                    Console.WriteLine($"{choreToAdd.Name} has been added and assigned an Id of {choreToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for roommate"):
                    Console.WriteLine("Roommate Id: ");
                    int      roommateId = int.Parse(Console.ReadLine());
                    Roommate roommate   = roommateRepo.GetById(roommateId);
                    Console.WriteLine($"{roommate.Firstname}:");
                    Console.WriteLine($"    Rent Portion:{roommate.RentPortion}");
                    Console.WriteLine($"    Room: {roommate.Room.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Unassigned chores"):
                    List <Chore> unassignedchores = choreRepo.UnassignedChores();
                    foreach (Chore c in unassignedchores)
                    {
                        Console.WriteLine(c.Name);
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Assign chore to roommate"):
                    List <Chore>    choreList    = choreRepo.GetAll();
                    List <Roommate> roommateList = roommateRepo.GetAll();
                    foreach (Chore c in choreList)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Please enter the id of the chore.");
                    int   choreIdToAdd = int.Parse(Console.ReadLine());
                    Chore chore1       = choreRepo.GetById(choreIdToAdd);
                    foreach (Roommate r in roommateList)
                    {
                        Console.WriteLine($"{r.Id} - {r.Firstname} {r.Lastname}");
                    }
                    Console.WriteLine("Please enter the id of the roommate.");
                    int      roommateIdToAdd = int.Parse(Console.ReadLine());
                    Roommate roommate1       = roommateRepo.GetById(roommateIdToAdd);
                    choreRepo.assignChore(roommateIdToAdd, choreIdToAdd);
                    Console.WriteLine($"{roommate1.Firstname} {roommate1.Lastname} has been assigned to {chore1.Name}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Update a room"):
                    List <Room> roomOptions = roomRepo.GetAll();
                    foreach (Room r in roomOptions)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name} Max Occupancy({r.MaxOccupancy})");
                    }

                    Console.Write("Which room would you like to update? ");
                    int  selectedRoomId = int.Parse(Console.ReadLine());
                    Room selectedRoom   = roomOptions.FirstOrDefault(r => r.Id == selectedRoomId);

                    Console.Write("New Name: ");
                    selectedRoom.Name = Console.ReadLine();

                    Console.Write("New Max Occupancy: ");
                    selectedRoom.MaxOccupancy = int.Parse(Console.ReadLine());

                    roomRepo.Update(selectedRoom);

                    Console.WriteLine($"Room has been successfully updated");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete room"):
                    List <Room> allRooms = roomRepo.GetAll();
                    foreach (Room r in allRooms)
                    {
                        Console.WriteLine($"{r.Id} - {r.Name}");
                    }
                    Console.WriteLine("Selecet the Id of the room to delete.");
                    int roomToDelete = int.Parse(Console.ReadLine());
                    roomRepo.Delete(roomToDelete);
                    break;

                case ("Update a chore"):
                    List <Chore> choreOptions = choreRepo.GetAll();
                    foreach (Chore c in choreOptions)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Which chore would you like to update?");
                    int   selectedChoreId = int.Parse(Console.ReadLine());
                    Chore selectedChore   = choreOptions.FirstOrDefault(c => c.Id == selectedChoreId);
                    Console.WriteLine("New Name: ");
                    selectedChore.Name = Console.ReadLine();
                    choreRepo.Update(selectedChore);
                    Console.WriteLine("Chore has been successfully updates.");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Delete chore"):
                    List <Chore> allChore = choreRepo.GetAll();
                    foreach (Chore c in allChore)
                    {
                        Console.WriteLine($"{c.Id} - {c.Name}");
                    }
                    Console.WriteLine("Selecet the Id of the chore to delete.");
                    int choreToDelete = int.Parse(Console.ReadLine());
                    choreRepo.Delete(choreToDelete);
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateChoreRepo  rcRepo       = new RoommateChoreRepo(CONNECTION_STRING);

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

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

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

            //Console.WriteLine("----------------------------");
            //Console.WriteLine("Getting Room with Id 1");

            //Room singleRoom = roomRepo.GetById(1);

            //Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            //Room bathroom = new Room
            //{
            //    Name = "Bathroom",
            //    MaxOccupancy = 1
            //};

            //roomRepo.Insert(bathroom);

            //Console.WriteLine("-------------------------------");
            //Console.WriteLine($"Added the new Room with id {bathroom.Id}");

            //Room washroom = new Room
            //{
            //    Id = 7,
            //    Name = "Washroom",
            //    MaxOccupancy = 2
            //};

            //roomRepo.Update(washroom);

            while (true)
            {
                Console.WriteLine();
                int selection = Menu();
                switch (selection)
                {
                case 1:
                    List <Roommate> allRoommates = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine(@$ "{roommate.Firstname} {roommate.Lastname} {roommate.RentPortion}
Living in the {roommate.Room.Name}");
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter room id to return who lives in that room");
                    string          roomyRoomString = Console.ReadLine();
                    int             roomyRoomId     = int.Parse(roomyRoomString);
                    List <Roommate> roomies         = roommateRepo.GetAllWithRoom(roomyRoomId);
                    foreach (Roommate roommate in roomies)
                    {
                        Console.WriteLine($"{roommate.Firstname} {roommate.Lastname}");
                    }
                    break;

                case 3:
                    Console.WriteLine("Roommate First Name:");
                    string FirstName = Console.ReadLine();
                    Console.WriteLine("Roommate Last Name:");
                    string LastName = Console.ReadLine();
                    Console.WriteLine("Rent Portion:");
                    string   RentString = Console.ReadLine();
                    int      RentInt    = Int32.Parse(RentString);
                    DateTime todaysDate = DateTime.Now;
                    Console.WriteLine("Room Id:");
                    string   RoomIdString = Console.ReadLine();
                    int      RoomIdInt    = Int32.Parse(RoomIdString);
                    Room     singleRoom   = roomRepo.GetById(RoomIdInt);
                    Roommate newRoomy     = new Roommate()
                    {
                        Firstname   = FirstName,
                        Lastname    = LastName,
                        RentPortion = RentInt,
                        MovedInDate = todaysDate,
                        Room        = singleRoom
                    };
                    roommateRepo.Insert(newRoomy);
                    break;

                case 4:
                    Console.WriteLine("Enter Roommate Id to Update:");
                    string   roomyString   = Console.ReadLine();
                    int      roomyInt      = Int32.Parse(roomyString);
                    Roommate roomyToUpdate = roommateRepo.GetById(roomyInt);

                    Console.WriteLine($"Enter updated roomy First Name from {roomyToUpdate.Firstname}:");
                    string firstName = Console.ReadLine();

                    Console.WriteLine($"Enter updated roomy Last Name from {roomyToUpdate.Lastname}");
                    string lastName = Console.ReadLine();

                    Console.WriteLine($"Update Rent Portion from {roomyToUpdate.RentPortion}");
                    string RentStringed = Console.ReadLine();
                    int    RentInted    = Int32.Parse(RentStringed);

                    Console.WriteLine($"Enter updated room Id from {roomyToUpdate.Room.Id}");
                    string   RoomyIdString    = Console.ReadLine();
                    int      RoomyIdInt       = Int32.Parse(RoomyIdString);
                    Room     updateSingleRoom = roomRepo.GetById(RoomyIdInt);
                    Roommate updatedRoomy     = new Roommate
                    {
                        Firstname   = firstName,
                        Lastname    = lastName,
                        RentPortion = RentInted,
                        MovedInDate = roomyToUpdate.MovedInDate,
                        Room        = updateSingleRoom,
                        Id          = roomyToUpdate.Id
                    };
                    roommateRepo.Update(updatedRoomy);

                    break;

                case 5:
                    Console.WriteLine("Enter Roommate id to kick from the house:");
                    string stringOfRoomyKick = Console.ReadLine();
                    int    intOfRoomyKick    = Int32.Parse(stringOfRoomyKick);
                    roommateRepo.Delete(intOfRoomyKick);
                    break;

                case 6:
                    Console.WriteLine("Enter roommate Id of roomy who needs some chores:");
                    string   rmString  = Console.ReadLine();
                    int      rmInt     = int.Parse(rmString);
                    Roommate lazyRoomy = roommateRepo.GetById(rmInt);

                    Console.WriteLine("Enter the name of the chore to complete");
                    string choreName = Console.ReadLine();
                    Chore  newChore  = new Chore()
                    {
                        Name = choreName
                    };
                    choreRepo.Insert(newChore);
                    Chore choreSelected = choreRepo.GetWithChoreName(newChore.Name);
                    rcRepo.InsertRC(lazyRoomy, choreSelected);
                    break;

                case 0:
                    Console.WriteLine("Goodbye");
                    return;

                default:
                    throw new Exception("Something went wrong...invalid selection");
                }
            }
Esempio n. 6
0
        public void UploadAccomodationRequests(ExcelFile fileUpload)
        {
            var    accomodations = new AccomodationRequest[_repository.GetAllStudents().Count()];
            var    file          = fileUpload.FileAccomodationRequests;
            string folderName    = "UploadAccomodationRequests";
            string webRootPath   = _hostingEnvironment.WebRootPath;
            string newPath       = Path.Combine(webRootPath, folderName);

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            if (file.Length > 0)
            {
                string sFileExtension = Path.GetExtension(file.FileName).ToLower();
                ISheet sheet;
                string fullPath = Path.Combine(newPath, file.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    file.CopyTo(stream);
                    stream.Position = 0;
                    if (sFileExtension == ".xls")
                    {
                        HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats
                        sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                    }
                    else
                    {
                        XSSFWorkbook hssfwb = new XSSFWorkbook(stream);               //This will read 2007 Excel format
                        sheet = hssfwb.GetSheetAt(0);                                 //get first sheet from workbook
                    }
                    IRow headerRow = sheet.GetRow(0);                                 //Get Header Row
                    int  cellCount = headerRow.LastCellNum;
                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File
                    {
                        IRow row = sheet.GetRow(i);
                        if (row == null)
                        {
                            continue;
                        }
                        if (row.Cells.All(d => d.CellType == CellType.Blank))
                        {
                            continue;
                        }
                        AccomodationRequest accomodationRequest = new AccomodationRequest();
                        for (int j = 0; j < 5; j++)
                        {
                            DormsPreferred dorm = new DormsPreferred();
                            if (row.GetCell(j + 1).ToString().Length > 0 && row.GetCell(j + 1).ToString() != "e")
                            {
                                dorm.DormName = row.GetCell(j + 1).ToString();
                                accomodationRequest.ArDorm.Add(dorm);
                            }
                            else
                            {
                                break;
                            }
                        }
                        for (int k = 0; k < 5; k++)
                        {
                            if (row.GetCell(k + 6).ToString() != "e")
                            {
                                RoomPreferred room = new RoomPreferred();
                                room.RoomNo = row.GetCell(k + 6).ToString();
                                accomodationRequest.ArRoom.Add(room);
                            }
                            else
                            {
                                break;
                            }
                        }
                        for (int l = 0; l < 2; l++)
                        {
                            if (row.GetCell(l + 11).ToString() != "e" && row.GetCell(l + 12).ToString() != "e" && row.GetCell(l + 13).ToString() != "e")
                            {
                                Roommate roommate = new Roommate();
                                roommate.FirstName = row.GetCell(l + 11).ToString();
                                roommate.LastName  = row.GetCell(l + 12).ToString();
                                roommate.Initial   = row.GetCell(l + 13).ToString();
                                accomodationRequest.ArRoommates.Add(roommate);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (row.GetCell(17).ToString() != "e")
                        {
                            accomodationRequest.LastComfortAccepted = row.GetCell(17).ToString();
                        }
                        //_repository.AddAccomodationRequestToDatabase(accomodationRequest);
                        string  cnp     = row.GetCell(18).ToString();
                        Student student = _repository.GetStudentByCNP(cnp);
                        student.AccomodationRequest   = accomodationRequest;
                        student.AccomodationRequestId = accomodationRequest.Id;
                        _repository.UpdateStudent(student);
                    }
                    //var students = _repository.GetStudentsOrderdById().ToList();
                    //for (int i = 0; i < accomodations.Count; i++)
                    //{
                    //    students[i].AccomodationRequest = accomodations[i];
                    //    students[i].AccomodationRequestId = accomodations[i].Id;
                    //}
                }
            }
        }
Esempio n. 7
0
 public Roommate Add(Roommate roomie)
 {
     _roomies.InsertOne(roomie);
     return(roomie);
 }
Esempio n. 8
0
        public List <Roommate> GetAllWithRoom(int roomId)
        {
            //  We must "use" the database connection.
            //  Because a database is a shared resource (other applications may be using it too) we must
            //  be careful about how we interact with it. Specifically, we Open() connections when we need to
            //  interact with the database and we Close() them when we're finished.
            //  In C#, a "using" block ensures we correctly disconnect from a resource even if there is an error.
            //  For database connections, this means the connection will be properly closed.
            using (SqlConnection conn = Connection)
            {
                // Note, we must Open() the connection, the "using" block doesn't do that for us.
                conn.Open();
                // We must "use" commands too.
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    // Here we setup the command with the SQL we want to execute before we execute it.
                    cmd.CommandText = "SELECT * FROM Roommate JOIN Room ON Room.Id = Roommate.RoomId WHERE roomId = @roomId";
                    cmd.Parameters.AddWithValue("@roomId", roomId);
                    // Execute the SQL in the database and get a "reader" that will give us access to the data.
                    SqlDataReader reader = cmd.ExecuteReader();

                    // A list to hold the roommates we retrieve from the database.
                    List <Roommate> roommates = new List <Roommate>();

                    // Read() will return true if there's more data to read
                    while (reader.Read())
                    {
                        // The "ordinal" is the numeric position of the column in the query results.
                        int idColumnPosition = reader.GetOrdinal("Id");

                        // We user the reader's GetXXX methods to get the value for a particular ordinal.
                        int idValue = reader.GetInt32(idColumnPosition);

                        int    firstNameColumnPosition = reader.GetOrdinal("FirstName");
                        string firstNameValue          = reader.GetString(firstNameColumnPosition);

                        int    lastNameColumnPosition = reader.GetOrdinal("LastName");
                        string lastNameValue          = reader.GetString(lastNameColumnPosition);

                        int rentPortionColumnPosition = reader.GetOrdinal("RentPortion");
                        int rentPortionValue          = reader.GetInt32(rentPortionColumnPosition);

                        int      moveInDateColumnPosition = reader.GetOrdinal("MoveInDate");
                        DateTime moveInDateValue          = reader.GetDateTime(moveInDateColumnPosition);

                        // Now let's create a new room object using the data from the database.
                        Room roommatesRoom = new Room()
                        {
                            Id           = roomId,
                            Name         = reader.GetString(reader.GetOrdinal("Name")),
                            MaxOccupancy = reader.GetInt32(reader.GetOrdinal("MaxOccupancy")),
                        };

                        // Now let's create a new roommate object using the data from the database.
                        Roommate roommate = new Roommate
                        {
                            Id          = idValue,
                            Firstname   = firstNameValue,
                            Lastname    = lastNameValue,
                            RentPortion = rentPortionValue,
                            MovedInDate = moveInDateValue,
                            Room        = roommatesRoom
                        };

                        // ...and add that roommate object to our list.
                        roommates.Add(roommate);
                    }

                    // We should Close() the reader. Unfortunately, a "using" block won't work here.
                    reader.Close();

                    // Return the list of roommates who whomever called this method.
                    return(roommates);
                }
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

            /*
             * Console.WriteLine("Getting All Rooms:");
             * Console.WriteLine();
             *
             * List<Room> allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             */
            Console.WriteLine("----------------------------");

            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("getting all the roommates");
            Console.WriteLine();
            List <Roommate> allRoommates = roommateRepo.GetAll();

            foreach (Roommate roommate in allRoommates)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}");
            }

            /*
             * Console.WriteLine("----------------------------");
             *
             * Console.WriteLine("Getting Room with Id 1");
             *
             * Room singleRoom = roomRepo.GetById(1);
             *
             * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");
             */

            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Roommate with Id 1");

            Roommate roommate1 = roommateRepo.GetById(1);

            Console.WriteLine($"{roommate1.Firstname} {roommate1.Lastname} {roommate1.Room}");
            Console.WriteLine("----------------------------");

            // getting roommates based on roomId

            Console.WriteLine("getting all the roommates and all their room info");
            List <Roommate> allRoommatesWithRoom = roommateRepo.GetRoommatesByRoomId(1);

            foreach (Roommate roommateWithRoom in allRoommatesWithRoom)
            {
                Console.WriteLine($"{roommateWithRoom.Id}: {roommateWithRoom.Firstname} {roommateWithRoom.Lastname} is assigned {roommateWithRoom.Room.Name}; \n pays {roommateWithRoom.RentPortion} move-in-date: {roommateWithRoom.MovedInDate}");
            }
            ;
            Console.WriteLine("----------------------------");

            Roommate newRoommate = new Roommate
            {
                Firstname   = "pablo",
                Lastname    = "nuts",
                MovedInDate = new DateTime(2020, 2, 22),
                RentPortion = 12,
                Room        = roomRepo.GetById(1)
            };

            //roommateRepo.Insert(newRoommate);
            //update
            roommateRepo.Update(newRoommate);
            Console.WriteLine($"updated juan to {newRoommate.Firstname}");
            Console.WriteLine("----------------------------");

            roommateRepo.Delete(2);

            /*
             * Room bathroom = new Room
             * {
             *  Name = "Bathroom",
             *  MaxOccupancy = 1
             * };
             *
             * roomRepo.Insert(bathroom);
             *
             */


            /*
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"Added the new Room with id {bathroom.Id}");
             *
             * bathroom.MaxOccupancy = 3;
             *
             * roomRepo.Update(bathroom);
             *
             *
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"updated the room to have max occupancy of {bathroom.MaxOccupancy}");
             */


            /*
             * foreach (Room room in allRooms)
             * {
             *  Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             * Console.WriteLine("-------------------------------");
             *
             * roomRepo.Delete(bathroom.Id);
             */
        }
Esempio n. 10
0
        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}");
            //}
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            Console.WriteLine("----------------------------");
            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);
        }
Esempio n. 12
0
        public List <Roommate> GetAllWithRoom(int roomId)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT rm.Id, rm.Firstname, rm.Lastname, rm.RentPortion, rm.MoveInDate, 
                                        rm.RoomId, r.Name, r.MaxOccupancy 
                                        FROM Roommate rm join room r on rm.RoomId = r.id
                                        where roomId = @roomId";
                    cmd.Parameters.AddWithValue("@roomId", roomId);


                    SqlDataReader   reader    = cmd.ExecuteReader();
                    List <Roommate> roommates = new List <Roommate>();


                    while (reader.Read())
                    {
                        int idColumnPosition = reader.GetOrdinal("Id");
                        int idValue          = reader.GetInt32(idColumnPosition);

                        int    FirstNameColumnPosition = reader.GetOrdinal("FirstName");
                        string FirstNameValue          = reader.GetString(FirstNameColumnPosition);

                        int    LastNameColumnPosition = reader.GetOrdinal("LastName");
                        string LastNameValue          = reader.GetString(LastNameColumnPosition);

                        int RentPortionColumnPosition = reader.GetOrdinal("RentPortion");
                        int RentPortionValue          = reader.GetInt32(RentPortionColumnPosition);

                        int      MovedInDateColumnPosition = reader.GetOrdinal("MoveInDate");
                        DateTime MovedInDateValue          = reader.GetDateTime(MovedInDateColumnPosition);

                        int RoomId = reader.GetInt32(reader.GetOrdinal("RoomId"));

                        string roomName = reader.GetString(reader.GetOrdinal("name"));

                        int maxOccupancy = reader.GetInt32(reader.GetOrdinal("MaxOccupancy"));

                        // Now let's create a new roommate object using the data from the database.
                        Roommate roommate = new Roommate
                        {
                            Id          = idValue,
                            Firstname   = FirstNameValue,
                            Lastname    = LastNameValue,
                            RentPortion = RentPortionValue,
                            MovedInDate = MovedInDateValue,
                            Room        = new Room()
                            {
                                Id           = RoomId,
                                Name         = roomName,
                                MaxOccupancy = maxOccupancy
                            }
                        };

                        // ...and add that roommate object to our list.
                        roommates.Add(roommate);
                    }

                    // We should Close() the reader. Unfortunately, a "using" block won't work here.
                    reader.Close();

                    // Return the list of roommates to whomever called this method.
                    return(roommates);
                }
            }
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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


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

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

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

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



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

            while (true)
            {
                Console.WriteLine();

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

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

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

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


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

                    roomRepo.Insert(AddedRoom);

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

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

                    roomRepo.Delete(roomId);

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

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

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

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

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

                    roomRepo.Update(UpdatedRoom);

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

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

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

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

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


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

                    roommateRepo.Insert(AddedRoommate);

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

                case 7:     //Edit a roommate's info

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

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

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

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

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

                    DateTime EditMoveInDate = DateTime.Now;

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

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

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

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

                    roommateRepo.Update(UpdatedRoommate);

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

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

                    roomRepo.Delete(roommateId);

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

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

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

                    Chore AddedChore = new Chore
                    {
                        Name = newChoreName,
                    };
                    choreRepo.Insert(AddedChore);
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new chore '{AddedChore.Name}' with id {AddedChore.Id}");
                    break;
                }
            }
        }
Esempio n. 14
0
        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}");
            }
        }
Esempio n. 15
0
        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");
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");

            Room singleRoom = roomRepo.GetById(1);

            Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");



            Room bathroom = new Room
            {
                Name         = "Bathroom",
                MaxOccupancy = 1
            };

            roomRepo.Insert(bathroom);

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


            bathroom.MaxOccupancy = 3;
            roomRepo.Update(bathroom);

            Room bathroomFromDb = roomRepo.GetById(bathroom.Id);

            Console.WriteLine($"{bathroomFromDb.Id} {bathroomFromDb.Name} {bathroomFromDb.MaxOccupancy}");
            Console.WriteLine("-------------------------------");


            roomRepo.Delete(bathroom.Id);
            allRooms = roomRepo.GetAll();
            foreach (Room room in allRooms)

            {
                Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
            }
            Console.WriteLine("-------------------------------");


            /////Implement the RoommateRepository class to include the following methods

            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   = "Andy",
                Lastname    = "Collins",
                RentPortion = 10,
                MovedInDate = new DateTime(2020, 11, 06),
                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}");
            }
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            Console.WriteLine("----------------------------");
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            Console.WriteLine("Getting All Roommatess:");
            Console.WriteLine();

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

            foreach (Roommate roommate in allRoommatess)
            {
                Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} lives in {roommate.Room.Name}");
            }

            Console.WriteLine("----------------------------");
            Console.WriteLine("roomate with id of 1");

            Roommate singleRoommate = roommateRepo.GetById(1);

            Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} lives in {singleRoommate.Room.Name}");



            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 UpdatedRoom = new Room
            {
                Name         = "Attic",
                MaxOccupancy = 1,
                Id           = 5
            };

            roomRepo.Update(UpdatedRoom);

            roomRepo.Delete(9);
        }
Esempio n. 18
0
    public static void NotifyRoomChange()
    {
        var context = GlobalHost.ConnectionManager.GetHubContext <NotifyHub>();

        context.Clients.All.OnRoomChanged(Roommate.Enum());
    }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
 public void RequestRoomUsers()
 {
     Clients.Caller.OnRoomChanged(Roommate.Enum());
 }
Esempio n. 21
0
        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}");
            }
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            //RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            //Console.WriteLine("----------------------------");
            //Console.WriteLine("Getting Room with Id 1");

            //Room singleRoom = roomRepo.GetById(1);

            //Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            //Room bathroom = new Room
            //{
            //    Name = "Bathroom",
            //    MaxOccupancy = 1
            //};

            //roomRepo.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;
Esempio n. 23
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            Console.WriteLine("----------------------------");
            Console.WriteLine("Getting Room with Id 1");

            Room singleRoom = roomRepo.GetById(1);

            Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");

            Room bathroom = new Room
            {
                Name         = "Bathroom",
                MaxOccupancy = 1
            };

            roomRepo.Insert(bathroom);

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

            bathroom.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);
        }
Esempio n. 24
0
        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;
            }
        }
Esempio n. 25
0
        public List <Roommate> GetAllWithRoom(int roomId)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT roommate.Id AS 'roomyId', FirstName, LastName, MoveInDate, RentPortion, room.Id AS 'roomId', room.Name AS 'roomName', room.MaxOccupancy AS 'roomOcc' 
                    FROM Roommate roommate JOIN Room room ON room.Id = Roommate.RoomId 
                    WHERE roommate.RoomId = @roomId";
                    cmd.Parameters.AddWithValue("@roomId", roomId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    List <Roommate> roommates = new List <Roommate>();

                    while (reader.Read())
                    {
                        int idColumnPosition = reader.GetOrdinal("roomyId");
                        int idValue          = reader.GetInt32(idColumnPosition);

                        string firstNameValue = reader.GetString(reader.GetOrdinal("FirstName"));

                        int    lastNameColumnPosition = reader.GetOrdinal("LastName");
                        string lastNameValue          = reader.GetString(lastNameColumnPosition);

                        int rentPortionColumnPosition = reader.GetOrdinal("RentPortion");
                        int rentPortion = reader.GetInt32(rentPortionColumnPosition);

                        int      moveInDateColumnPosition = reader.GetOrdinal("MoveInDate");
                        DateTime moveInDate = reader.GetDateTime(moveInDateColumnPosition);

                        int roomIdColumnPosition = reader.GetOrdinal("roomId");
                        int roomIdValue          = reader.GetInt32(roomIdColumnPosition);


                        int    roomNameColumnPosition = reader.GetOrdinal("roomName");
                        string roomName = reader.GetString(roomNameColumnPosition);

                        int roomOcc      = reader.GetOrdinal("roomOcc");
                        int roomOccValue = reader.GetInt32(roomOcc);

                        Roommate roommate = new Roommate
                        {
                            Id          = idValue,
                            Firstname   = firstNameValue,
                            Lastname    = lastNameValue,
                            RentPortion = rentPortion,
                            MovedInDate = moveInDate,
                            Room        = new Room
                            {
                                Id           = roomIdValue,
                                Name         = roomName,
                                MaxOccupancy = roomOccValue
                            }
                        };
                        roommates.Add(roommate);
                    }
                    reader.Close();

                    return(roommates);
                }
            }
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            ChoreRepository    choreRepo    = new ChoreRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);
            bool runProgram = true;

            while (runProgram)
            {
                string selection = GetMenuSelection();

                switch (selection)
                {
                case ("Show all rooms"):
                    List <Room> rooms = roomRepo.GetAll();
                    foreach (Room r in rooms)
                    {
                        Console.WriteLine($"{r.Name} has an Id of {r.Id} and a max occupancy of {r.MaxOccupancy}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Search for room"):
                    Console.Write("Room Id: ");
                    int id = int.Parse(Console.ReadLine());

                    Room room = roomRepo.GetById(id);

                    Console.WriteLine($"{room.Id} - {room.Name} Max Occupancy({room.MaxOccupancy})");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a room"):
                    Console.Write("Room name: ");
                    string name = Console.ReadLine();

                    Console.Write("Max occupancy: ");
                    int max = int.Parse(Console.ReadLine());

                    Room roomToAdd = new Room()
                    {
                        Name         = name,
                        MaxOccupancy = max
                    };

                    roomRepo.Insert(roomToAdd);

                    Console.WriteLine($"{roomToAdd.Name} has been added and assigned an Id of {roomToAdd.Id}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Show all chores"):
                    List <Chore> chores = choreRepo.GetAll();
                    foreach (Chore c in chores)
                    {
                        Console.WriteLine($"{c.Name} has an Id of {c.Id}");
                    }
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Add a chore"):
                    Console.Write("Chore name: ");
                    string choreName = Console.ReadLine();

                    Chore choreToAdd = new Chore()
                    {
                        Name = choreName
                    };

                    choreRepo.Insert(choreToAdd);
                    break;

                case ("Search for roommate"):
                    Console.Write("Roommate Id: ");
                    int Roommateid = int.Parse(Console.ReadLine());

                    Roommate roommate = roommateRepo.GetById(Roommateid);

                    Console.WriteLine($"Name: {roommate.FirstName}, Rent Portion: {roommate.RentPortion}%, Room: {roommate.RoomName}");
                    Console.Write("Press any key to continue");
                    Console.ReadKey();
                    break;

                case ("Exit"):
                    runProgram = false;
                    break;
                }
            }
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            /* RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);
             *
             * Console.WriteLine("Getting All Rooms:");
             * Console.WriteLine();
             *
             * List<Room> allRooms = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms)
             * {
             *   Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }
             *
             * Console.WriteLine("----------------------------");
             * Console.WriteLine("Getting Room with Id 1");
             *
             * Room singleRoom = roomRepo.GetById(1);
             *
             * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");
             *
             * Room bathroom = new Room
             * {
             *   Name = "Bathroom",
             *   MaxOccupancy = 1
             * };
             *
             * roomRepo.Insert(bathroom);
             *
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"Added the new Room with id {bathroom.Id}");
             * Console.WriteLine("-------------------------------");
             * bathroom.Name = "Outhouse";
             * bathroom.MaxOccupancy = 1;
             *
             * roomRepo.Update(bathroom);
             * Room UpdateTest = roomRepo.GetById(bathroom.Id);
             * Console.WriteLine($"Updated: {UpdateTest.Id} {UpdateTest.Name} {UpdateTest.MaxOccupancy}");
             * Console.WriteLine("-------------------------------");
             * roomRepo.Delete(bathroom.Id);
             *
             * List<Room> allRooms2 = roomRepo.GetAll();
             *
             * foreach (Room room in allRooms2)
             * {
             *   Console.WriteLine($"{room.Id} {room.Name} {room.MaxOccupancy}");
             * }*/



            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

            int  userEntry      = 1;
            bool mainWhileCheck = true;

            while (mainWhileCheck != false)
            {
                Console.WriteLine("Welcome to Roommate Manager!");
                Console.WriteLine("Choose an option below:");
                Console.WriteLine("");
                Console.WriteLine("1) Get all Roommates");
                Console.WriteLine("2) Get Roommate by Id/Edit");
                Console.WriteLine("3) Get First Roommate by Room");
                Console.WriteLine("4) Get Roommates by Room");
                Console.WriteLine("5) Add new Rommmate");

                Console.WriteLine("6) Delete a Roommate");
                Console.WriteLine("0) Exit");
                Console.WriteLine("");
                userEntry = int.Parse(Console.ReadLine());
                Console.WriteLine("");
                if (userEntry == 0)
                {
                    mainWhileCheck = false;
                    break;
                }
                else if (userEntry == 1)
                {
                    Console.WriteLine("Getting All Roommates:");
                    Console.WriteLine();

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

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room}");
                    }
                    Console.WriteLine("----------------------------");
                }
                else if (userEntry == 2)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the id of the roommate you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());

                    Console.WriteLine($"Getting Roommate with Id {byIdEntry}");

                    Roommate singleRoommate = roommateRepo.GetById(byIdEntry);

                    Console.WriteLine($"{singleRoommate.Id} {singleRoommate.Firstname} {singleRoommate.Lastname} {singleRoommate.RentPortion} {singleRoommate.MovedInDate} {singleRoommate.Room}");
                    Console.WriteLine("----------------------------");

                    string editCheck = "a";
                    bool   editWhile = true;
                    Console.WriteLine("");
                    Console.Write("Do you want to Edit this Entry Y/N:");
                    editCheck = Console.ReadLine();
                    Console.WriteLine("");
                    if (editCheck == "y" || editCheck == "Y")
                    {
                        int editSelect = 1;
                        while (editWhile == true)
                        {
                            Console.WriteLine("What do you want to edit:");
                            Console.WriteLine("");
                            Console.WriteLine("1) First Name");
                            Console.WriteLine("2) Last Name");
                            Console.WriteLine("3) Rent Portion");
                            Console.WriteLine("4) Move in Date");
                            Console.WriteLine("5) Assigned Room Id");
                            Console.WriteLine("0) Edit Complete");

                            editSelect = int.Parse(Console.ReadLine());

                            if (editSelect == 0)
                            {
                                editWhile = false;
                            }
                            else if (editSelect == 1)
                            {
                                Console.WriteLine($"The entry's First Name is {singleRoommate.Firstname}. What would you like to change it to?");
                                singleRoommate.Firstname = Console.ReadLine();
                                Console.WriteLine("");
                            }
                            else if (editSelect == 2)
                            {
                                Console.WriteLine($"The entry's Last Name is {singleRoommate.Lastname}. What would you like to change it to?");
                                singleRoommate.Lastname = Console.ReadLine();
                            }
                            else if (editSelect == 3)
                            {
                                Console.WriteLine($"The entry's Rent Portion is {singleRoommate.RentPortion}. What would you like to change it to?");
                                singleRoommate.RentPortion = int.Parse(Console.ReadLine());
                            }
                            else if (editSelect == 4)
                            {
                                Console.WriteLine($"The entry's Move in Day is {singleRoommate.MovedInDate}. What would you like to change it to? (Year, Month, Day)");
                                singleRoommate.MovedInDate = DateTime.Parse(Console.ReadLine());
                            }
                            else if (editSelect == 5)
                            {
                                Console.WriteLine($"The entry's Assigned Room Id is {singleRoommate.RoomId}. What would you like to change it to?");
                                singleRoommate.RoomId = int.Parse(Console.ReadLine());
                            }
                        }
                        roommateRepo.Update(singleRoommate);
                        Roommate UpdatedTest = roommateRepo.GetById(singleRoommate.Id);
                        Console.WriteLine($"Updated: {UpdatedTest.Id} {UpdatedTest.Firstname} {UpdatedTest.Lastname} {UpdatedTest.RentPortion} {UpdatedTest.MovedInDate}");
                        Console.WriteLine("-------------------------------");
                        Console.WriteLine("");
                    }
                    else
                    {
                        Console.WriteLine("");
                    }
                }
                else if (userEntry == 3)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the Roomid of the roommate you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());
                    Console.WriteLine($"Getting Latest Roommate with RoomId {byIdEntry}");
                    Roommate singleRoommate2 = roommateRepo.GetByRoom(byIdEntry);

                    Console.WriteLine($"{singleRoommate2.Id} {singleRoommate2.Firstname} {singleRoommate2.Lastname} {singleRoommate2.RentPortion} {singleRoommate2.MovedInDate} {singleRoommate2.Room.Name} {singleRoommate2.Room.MaxOccupancy} {singleRoommate2.Room.MaxOccupancy}");
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("");
                }
                else if (userEntry == 4)
                {
                    int byIdEntry = 1;
                    Console.Write("Type in the Roomid of the roommates you want to find:");
                    byIdEntry = int.Parse(Console.ReadLine());
                    Console.WriteLine($"Getting Roommates with RoomId {byIdEntry}");
                    List <Roommate> allRoommatesByRoom = roommateRepo.GetAllWithRoom(byIdEntry);

                    foreach (Roommate roommate in allRoommatesByRoom)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.Room.Name}");
                    }
                    Console.WriteLine("");
                }
                else if (userEntry == 5)
                {
                    Roommate roomy1 = new Roommate
                    {
                        Firstname   = "Matt",
                        Lastname    = "Patt",
                        RentPortion = 40,
                        MovedInDate = new DateTime(2020, 09, 15),
                        Room        = null,
                        RoomId      = 3
                    };
                    Console.WriteLine("");
                    Console.WriteLine("Input information for a new Roommate:");
                    Console.Write("First Name:");
                    roomy1.Firstname = Console.ReadLine();
                    Console.Write("Last Name:");
                    roomy1.Lastname = Console.ReadLine();
                    Console.Write("Rent Portion:");
                    roomy1.RentPortion = int.Parse(Console.ReadLine());
                    Console.Write("Move In Date (Year, Month, Day):");
                    roomy1.MovedInDate = DateTime.Parse(Console.ReadLine());
                    Console.Write("Assigned Room Id:");
                    roomy1.RoomId = int.Parse(Console.ReadLine());

                    Console.Write("Press any key to submit the Roommate:");
                    Console.ReadLine();
                    roommateRepo.Insert(roomy1);
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine($"Added the new Roommate with id {roomy1.Id}");
                    Console.WriteLine("-------------------------------");
                    Console.WriteLine("");
                }
                else if (userEntry == 6)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Which Roommate would you like to Delete?");
                    List <Roommate> allRoommates = roommateRepo.GetAll();

                    foreach (Roommate roommate in allRoommates)
                    {
                        Console.WriteLine($"{roommate.Id}) {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate}");
                    }
                    roommateRepo.Delete(int.Parse(Console.ReadLine()));

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

                    foreach (Roommate roommate in allRoommates2)
                    {
                        Console.WriteLine($"{roommate.Id} {roommate.Firstname} {roommate.Lastname} {roommate.RentPortion} {roommate.MovedInDate} {roommate.RoomId}");
                    }
                    Console.WriteLine("");
                }
            }
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            RoomRepository roomRepo = new RoomRepository(CONNECTION_STRING);

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

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

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

            /*Console.WriteLine("----------------------------");
             * Console.WriteLine("Getting Room with Id 1");
             *
             * Room singleRoom = roomRepo.GetById(1);
             *
             * Console.WriteLine($"{singleRoom.Id} {singleRoom.Name} {singleRoom.MaxOccupancy}");
             *
             * Room bathroom = new Room
             * {
             *  Name = "Bathroom",
             *  MaxOccupancy = 1
             * };
             *
             * roomRepo.Insert(bathroom);
             *
             * Console.WriteLine("-------------------------------");
             * Console.WriteLine($"Added the new Room with id {bathroom.Id}");
             *
             * bathroom.MaxOccupancy = 3;
             * roomRepo.Update(bathroom);
             *
             * 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}");
            }
        }
Esempio n. 29
0
        /// >>>>>>>>>
        /// ...We'll add some methods shortly...
        /// <summary>
        ///  Get a list of all Roommatess in the database
        /// </summary>
        public List <Roommate> GetAll()
        {
            //  We must "use" the database connection.
            //  Because a database is a shared resource (other applications may be using it too) we must
            //  be careful about how we interact with it. Specifically, we Open() connections when we need to
            //  interact with the database and we Close() them when we're finished.
            //  In C#, a "using" block ensures we correctly disconnect from a resource even if there is an error.
            //  For database connections, this means the connection will be properly closed.
            using (SqlConnection conn = Connection)
            {
                // Note, we must Open() the connection, the "using" block doesn't do that for us.
                conn.Open();

                // We must "use" commands too.
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    // Here we setup the command with the SQL we want to execute before we execute it.
                    cmd.CommandText = "SELECT Id, Firstname, Lastname, MoveInDate FROM Roommate";

                    // Execute the SQL in the database and get a "reader" that will give us access to the data.
                    SqlDataReader reader = cmd.ExecuteReader();

                    // A list to hold the rooms we retrieve from the database.
                    List <Roommate> roommates = new List <Roommate>();

                    // Read() will return true if there's more data to read
                    while (reader.Read())
                    {
                        // The "ordinal" is the numeric position of the column in the query results.
                        //  For our query, "Id" has an ordinal value of 0 and "Name" is 1.
                        int idColumnPosition = reader.GetOrdinal("Id");

                        // We user the reader's GetXXX methods to get the value for a particular ordinal.
                        int idValue = reader.GetInt32(idColumnPosition);

                        int    FirstnamePosition = reader.GetOrdinal("Firstname");
                        string Firstname         = reader.GetString(FirstnamePosition);

                        int    LastnamePosition = reader.GetOrdinal("Lastname");
                        string Lastname         = reader.GetString(LastnamePosition);

                        int      MoveInDatePosition = reader.GetOrdinal("MoveInDate");
                        DateTime MoveInDate         = reader.GetDateTime(MoveInDatePosition);

                        // Now let's create a new room object using the data from the database.
                        Roommate roommate = new Roommate
                        {
                            Id         = idValue,
                            Firstname  = Firstname,
                            Lastname   = Lastname,
                            MoveInDate = MoveInDate
                        };

                        // ...and add that room object to our list.
                        roommates.Add(roommate);
                    }

                    // We should Close() the reader. Unfortunately, a "using" block won't work here.
                    reader.Close();

                    // Return the list of rooms who whomever called this method.
                    return(roommates);
                }
            }
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            RoomRepository     roomRepo     = new RoomRepository(CONNECTION_STRING);
            RoommateRepository roommateRepo = new RoommateRepository(CONNECTION_STRING);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    ;
                    break;
                }
                break;
                ;
            }



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

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


            //}
            //break;



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

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