public int Total(string search, bool?confirmed, int astronomerId, AstronomerType astronomerType) { return(this.db .Discoveries .Filter(search) .Confirmed(confirmed) .ByAstronomerType(astronomerId, astronomerType) .Count()); }
public IEnumerable <ListDiscoveriesServiceModel> All( int page, int pageSize, string search, bool?confirmed, int astronomerId, AstronomerType astronomerType) { return(this.db .Discoveries .OrderByDescending(d => d.DateMade) .Filter(search) .Confirmed(confirmed) .ByAstronomerType(astronomerId, astronomerType) .Skip((page - 1) * pageSize) .Take(pageSize) .ProjectTo <ListDiscoveriesServiceModel>() .ToList()); }
public static IQueryable <Discovery> ByAstronomerType(this IQueryable <Discovery> discoveries, int astronomerId, AstronomerType astronomerType) { if (astronomerType == AstronomerType.All) { return(discoveries .Where(d => d.Pioneers.Any(p => p.PioneerId == astronomerId) || d.Observers.Any(o => o.ObserverId == astronomerId))); } else if (astronomerType == AstronomerType.Pioneer) { return(discoveries .Where(d => d.Pioneers.Any(p => p.PioneerId == astronomerId))); } else if (astronomerType == AstronomerType.Observer) { return(discoveries .Where(d => d.Observers.Any(o => o.ObserverId == astronomerId))); } return(discoveries); }