2011-03-02 20:18:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Portoa.Persistence;
|
2011-02-26 01:08:38 +00:00
|
|
|
|
using Portoa.Search;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
|
2011-02-26 01:08:38 +00:00
|
|
|
|
namespace VideoGameQuotes.Web.Search {
|
2011-03-02 20:18:33 +00:00
|
|
|
|
public class SearchService<T, TId> : ISearchService<T, TId> where T : IIdentifiable<TId> {
|
|
|
|
|
private readonly IRepository<T, TId> repository;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
|
2011-03-02 20:18:33 +00:00
|
|
|
|
public SearchService(IRepository<T, TId> repository) {
|
2011-02-25 23:36:21 +00:00
|
|
|
|
this.repository = repository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
2011-03-02 20:18:33 +00:00
|
|
|
|
public IEnumerable<T> FindByIds(IEnumerable<TId> ids) {
|
2011-02-25 23:36:21 +00:00
|
|
|
|
return repository
|
|
|
|
|
.Records
|
|
|
|
|
.Where(entity => ids.ToArray().Contains(entity.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<T> GetAllIndexableRecords() {
|
|
|
|
|
return repository.Records;
|
|
|
|
|
}
|
2011-03-02 20:18:33 +00:00
|
|
|
|
|
|
|
|
|
public TId ConvertIdFromStringValue(string idValue) {
|
|
|
|
|
return (TId)Convert.ChangeType(idValue, typeof(TId));
|
|
|
|
|
}
|
2011-02-25 23:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|