vgquotes/Src/VideoGameQuotes.Web/Services/SystemService.cs

53 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
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);
GamingSystem FindById(int id);
void Delete(int id);
IEnumerable<Game> GetGamesForSystem(GamingSystem system);
}
public class SystemService : ISystemService {
private readonly IRepository<GamingSystem> repository;
private readonly IRepository<Game> gameRepository;
public SystemService(IRepository<GamingSystem> repository, IRepository<Game> gameRepository) {
this.repository = repository;
this.gameRepository = gameRepository;
}
[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);
}
[UnitOfWork]
public GamingSystem FindById(int id) {
return repository.FindById(id);
}
[UnitOfWork]
public void Delete(int id) {
repository.Delete(id);
}
public IEnumerable<Game> GetGamesForSystem(GamingSystem system) {
return gameRepository
.Records
.Where(game => game.Systems.Contains(system));
}
}
}