75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using Portoa.Persistence;
|
|||
|
using VideoGameQuotes.Api;
|
|||
|
|
|||
|
namespace VideoGameQuotes.Web.Services {
|
|||
|
public interface IQuoteService {
|
|||
|
Game GetGame(int id);
|
|||
|
IEnumerable<Game> GetAllGames();
|
|||
|
IEnumerable<GamingSystem> GetAllSystems();
|
|||
|
IEnumerable<Publisher> GetAllPublishers();
|
|||
|
Quote SaveQuote(Quote quote);
|
|||
|
Quote GetQuote(int id);
|
|||
|
Publisher GetPublisher(int id);
|
|||
|
GamingSystem GetSystem(int systemId);
|
|||
|
}
|
|||
|
|
|||
|
public class QuoteService : IQuoteService {
|
|||
|
private readonly IRepository<Quote> quoteRepository;
|
|||
|
private readonly IRepository<Game> gameRepository;
|
|||
|
private readonly IRepository<GamingSystem> systemRepository;
|
|||
|
private readonly IRepository<Publisher> publisherRepository;
|
|||
|
|
|||
|
public QuoteService(
|
|||
|
IRepository<Quote> quoteRepository,
|
|||
|
IRepository<Game> gameRepository,
|
|||
|
IRepository<GamingSystem> systemRepository,
|
|||
|
IRepository<Publisher> publisherRepository
|
|||
|
) {
|
|||
|
this.quoteRepository = quoteRepository;
|
|||
|
this.gameRepository = gameRepository;
|
|||
|
this.systemRepository = systemRepository;
|
|||
|
this.publisherRepository = publisherRepository;
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Game GetGame(int id) {
|
|||
|
return gameRepository.FindById(id);
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public IEnumerable<Game> GetAllGames() {
|
|||
|
return gameRepository.Records;
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public IEnumerable<Api.GamingSystem> GetAllSystems() {
|
|||
|
return systemRepository.Records;
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public IEnumerable<Publisher> GetAllPublishers() {
|
|||
|
return publisherRepository.Records;
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Quote SaveQuote(Quote quote) {
|
|||
|
return quoteRepository.Save(quote);
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Quote GetQuote(int id) {
|
|||
|
return quoteRepository.FindById(id);
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Publisher GetPublisher(int id) {
|
|||
|
return publisherRepository.FindById(id);
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public GamingSystem GetSystem(int systemId) {
|
|||
|
return systemRepository.FindById(systemId);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|