Select In list of object but the object also contains a list

  • Thread starter Thread starter tendaimare
  • Start date Start date
T

tendaimare

Guest
In my library app I have a Student class and a Book Class and a StudentBooks class. The Student class also contains a list of StudentBooks - a list of books the student has borrowed and the duedate.

public class Student
{
public Student(int id,string name,string surname,string gender,int age)
{
ID = id;
Name = name;
Surname = surname;
Gender = gender;
Age = age;
}
public int ID { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Gender { get; set; }
public int Age { get; set; }

public List<StudentBooks> studentBooks = new List<StudentBooks>();
public List<StudentFines> studentFines = new List<StudentFines>();
}

The Book class

public class Book
{
public Book( int id,string name,string author)
{
ID = id;
Name = name;
Author = author;
}
public int ID { get; set; }
public string Name { get; set; }
public string Author { get; set; }
}


StudentBooks Class

public class StudentBooks
{
public Book book { get; set; }
public DateTime DueDate { get; set; }
public StudentBooks(Book _book, DateTime _dueDate)
{
book = _book;
DueDate = _dueDate;
}
}
and then the library class
public class Library
{
public static readonly List<Book> Books = new List<Book>();
public static readonly List<Employee> Employees = new List<Employee>();
public static void PopulateBooks()
{
Books.Add(new Book(1,"Mpho Search","Gilbert"));

Books.Add(new Book(12, "Sleep walking", "Bob Chiffy"));
Books.Add(new Book(13, "Zen lifestyle", "Viltip Qwerty"));
}
public static void PopulateEmployees()
{
Employees.Add(new Employee(1, "Themba","Lancing","Male",23,"Themba","Themba@123"));

Employees.Add(new Employee(5, "Lisa", "Bundy", "Female", 49,"Lisa","Lisa@123"));
}
public static readonly List<Student> Students = new List<Student>();
public static void PopulateStudents()
{
Students.Add(new Student(1, "Monalisa", "Enerst", "Male", 23));
Students.Add(new Student(2, "Fredrick", "Makanda", "Male", 38));

Students.Add(new Student(15, "Tererai", "Mashava", "Female", 25));
}
}
I want to be able to come up with a list of students and the corresponding books that they have borrowed. Any ideas on how I can go about it.


If you think it you can achieve it

Continue reading...
 
Back
Top