2011-02-23 21:53:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-22 09:39:59 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Portoa.Persistence;
|
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web.Services {
|
|
|
|
|
public interface ISystemService {
|
|
|
|
|
IEnumerable<GamingSystem> FindByNameOrAbbreviation(string name, string abbreviation);
|
|
|
|
|
GamingSystem Save(GamingSystem system);
|
2011-02-23 21:53:51 +00:00
|
|
|
|
GamingSystem FindById(int id);
|
2011-02-24 01:10:52 +00:00
|
|
|
|
void Delete(int id);
|
|
|
|
|
IEnumerable<Game> GetGamesForSystem(GamingSystem system);
|
2011-02-22 09:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SystemService : ISystemService {
|
|
|
|
|
private readonly IRepository<GamingSystem> repository;
|
2011-02-24 01:10:52 +00:00
|
|
|
|
private readonly IRepository<Game> gameRepository;
|
2011-02-22 09:39:59 +00:00
|
|
|
|
|
2011-02-24 01:10:52 +00:00
|
|
|
|
public SystemService(IRepository<GamingSystem> repository, IRepository<Game> gameRepository) {
|
2011-02-22 09:39:59 +00:00
|
|
|
|
this.repository = repository;
|
2011-02-24 01:10:52 +00:00
|
|
|
|
this.gameRepository = gameRepository;
|
2011-02-22 09:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<GamingSystem> FindByNameOrAbbreviation(string name, string abbreviation) {
|
|
|
|
|
return repository
|
|
|
|
|
.Records
|
|
|
|
|
.Where(system => system.Abbreviation == abbreviation || system.Name == name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public GamingSystem Save(GamingSystem system) {
|
|
|
|
|
return repository.Save(system);
|
|
|
|
|
}
|
2011-02-23 21:53:51 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public GamingSystem FindById(int id) {
|
|
|
|
|
return repository.FindById(id);
|
|
|
|
|
}
|
2011-02-24 01:10:52 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public void Delete(int id) {
|
|
|
|
|
repository.Delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Game> GetGamesForSystem(GamingSystem system) {
|
|
|
|
|
return gameRepository
|
|
|
|
|
.Records
|
|
|
|
|
.Where(game => game.Systems.Contains(system));
|
|
|
|
|
}
|
2011-02-22 09:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|