vgquotes/Src/VideoGameQuotes.Api/Persistence/SearchService.cs
2011-02-25 23:36:21 +00:00

32 lines
811 B
C#

using System.Collections.Generic;
using System.Linq;
using Portoa.Persistence;
namespace VideoGameQuotes.Api.Persistence {
public interface ISearchService<T> where T : Entity<T, int> {
IEnumerable<T> FindByIds(IEnumerable<int> ids);
IEnumerable<T> GetAllIndexableRecords();
}
public class SearchService<T> : ISearchService<T> where T : Entity<T, int> {
private readonly IRepository<T> repository;
public SearchService(IRepository<T> repository) {
this.repository = repository;
}
[UnitOfWork]
public IEnumerable<T> FindByIds(IEnumerable<int> ids) {
return repository
.Records
.Where(entity => ids.ToArray().Contains(entity.Id));
}
[UnitOfWork]
public IEnumerable<T> GetAllIndexableRecords() {
return repository.Records;
}
}
}