If you want to have separate method in the Author
class like you asked in the question, it could look like:
public class Author
{
public Author()
{ }
public int _AuthorID { get; set; }
public string _AuthorName { get; set; }
public List<Paper> _Papers { get; set; }
public bool HasPapersForYear(int year)
{
return _Papers.Any(_paper => _paper._Year == year);
}
public bool HasPapersForYears(int startYear, int endYear)
{
return _Papers.Any(_paper => _paper._Year >= startYear && _paper._Year <= endYear);
}
}
And old methods are changed:
public List<Author> GetAuthorsByYear(List<Author> _fullList, int _year)
{
return _fullList.Where(_author => _author.HasPapersForYear(_year)).ToList();
}
public List<Author> GetAuthorsBetweenYears(List<Author> _fullList, int _startYear, int _endYear)
{
return _fullList.Where(_author => _author.HasPapersForYears(_startYear,_endYear)).ToList();
}
Also about the part of Venue and CoAuthors
public List<int> GetCoAuthorsByYear(int _year)
{
var coAuthors = new List<int>();
foreach(var paper in _Papers.Where(_paper => _paper._Year == _year))
{
coAuthors.AddRange(paper._CoAuthors);
}
return coAuthors;
}
public List<int> GetCoAuthorsBetweenYears(int _startYear, int _endYear)
{
var coAuthors = new List<int>();
foreach(var paper in _Papers.Where(_paper => _paper._Year >= _startYear && _paper._Year <= _endYear))
{
coAuthors.AddRange(paper._CoAuthors);
}
return coAuthors;
}
public List<int> GetVenuesByYear(int _year)
{
var venues = new List<int>();
foreach(var paper in _Papers.Where(_paper => _paper._Year == _year))
{
venues.Add(paper._VenueID);
}
return venues;
}
public List<int> GetVenuesBetweenYears(int _startYear, int _endYear)
{
var venues = new List<int>();
foreach(var paper in _Papers.Where(_paper => _paper._Year >= _startYear && _paper._Year <= _endYear))
{
venues.Add(paper._VenueID);
}
return venues;
}
This code could be refactored sure.
5
solved Return list of custom class using Linq