Hi,
I'm stuck trying to find a solution to this problem. Its a question taken from an exam for an interview.
I have this object model:
Department: DepartmentId, Name
TeacherTeacherId, FirstName, LastName, DateOfBirth, AnnualSalary, DepartmentId
CourseCourseId, Name, TeacherId, DepartmentId
Student: StudentId, FirstName, LastName, DateOfBirth, AverageScore, DepartmentId
Department has a 1 to many relationship with Teacher, Student and Course.
Teacher has a 1 to many relationship with Course
Student has a many to many relationship with Course
In a previous question I asked on here I asked how to create an interface between Student and Teacher called IPeople to highlight all commonality. I was pointed in the right direction and came up with
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace School.Code
{
public interface IPeople
{
string FirstName
{
get;
set;
}
string LastName
{
get;
set;
}
Int64 DepartmentId
{
get;
set;
}
DateTime DateOfBirth
{
get;
}
}
}
I then needed to create an IENumerable value of IPeople which I did using
public IEnumerable<IPeople> GetAllIPeople()
{
foreach (IPeople person in GetAllTeachers())
{
yield return person;
}
foreach (IPeople person in GetAllStudents())
{
yield return person;
}
}
How ever I am stuck with the next part of this.
The question is. Write method to get all IPeople for a Course - Write a method in the SchoolManager to get all IPeople for a particular Course. Your method should return an IENumerable of IPeople and make use of the existing GetAllIPeople method you've just written in the SchoolManager.
Now at first I thought this would be easy and should just use .where(c => c.CourseId == cId) where cId was passed into the method. How ever CourseId isnt in the interface as its not a common property between Student and Teacher. I do know because of the relationships between the objects that the Course, Student and Teacher will all share the same DepartmentID.
I am however completely lost as to how I produce an answer to this question. If anyone can point me in the right direction I would be grateful.