2011-02-13 09:55:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-14 11:01:31 +00:00
|
|
|
|
using System.Linq;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
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();
|
2011-02-13 09:55:01 +00:00
|
|
|
|
IEnumerable<Category> GetAllCategories();
|
2011-02-12 23:53:43 +00:00
|
|
|
|
Quote SaveQuote(Quote quote);
|
|
|
|
|
Quote GetQuote(int id);
|
|
|
|
|
Publisher GetPublisher(int id);
|
|
|
|
|
GamingSystem GetSystem(int systemId);
|
2011-02-13 09:55:01 +00:00
|
|
|
|
Category GetCategory(int categoryId);
|
2011-02-14 02:50:33 +00:00
|
|
|
|
Category SaveCategory(Category category);
|
2011-02-14 11:01:31 +00:00
|
|
|
|
IEnumerable<Quote> GetMostRecentQuotes(int limit);
|
2011-02-12 23:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class QuoteService : IQuoteService {
|
|
|
|
|
private readonly IRepository<Quote> quoteRepository;
|
|
|
|
|
private readonly IRepository<Game> gameRepository;
|
|
|
|
|
private readonly IRepository<GamingSystem> systemRepository;
|
|
|
|
|
private readonly IRepository<Publisher> publisherRepository;
|
2011-02-13 09:55:01 +00:00
|
|
|
|
private readonly IRepository<Category> categoryRepository;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
|
|
|
|
|
public QuoteService(
|
|
|
|
|
IRepository<Quote> quoteRepository,
|
|
|
|
|
IRepository<Game> gameRepository,
|
|
|
|
|
IRepository<GamingSystem> systemRepository,
|
2011-02-13 09:55:01 +00:00
|
|
|
|
IRepository<Publisher> publisherRepository, IRepository<Category> categoryRepository
|
|
|
|
|
) {
|
2011-02-12 23:53:43 +00:00
|
|
|
|
this.quoteRepository = quoteRepository;
|
2011-02-13 09:55:01 +00:00
|
|
|
|
this.categoryRepository = categoryRepository;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
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]
|
2011-02-13 09:55:01 +00:00
|
|
|
|
public IEnumerable<GamingSystem> GetAllSystems() {
|
2011-02-12 23:53:43 +00:00
|
|
|
|
return systemRepository.Records;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<Publisher> GetAllPublishers() {
|
|
|
|
|
return publisherRepository.Records;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-13 09:55:01 +00:00
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<Category> GetAllCategories() {
|
|
|
|
|
return categoryRepository.Records;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-12 23:53:43 +00:00
|
|
|
|
[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);
|
|
|
|
|
}
|
2011-02-13 09:55:01 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public Category GetCategory(int categoryId) {
|
|
|
|
|
return categoryRepository.FindById(categoryId);
|
|
|
|
|
}
|
2011-02-14 02:50:33 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public Category SaveCategory(Category category) {
|
|
|
|
|
return categoryRepository.Save(category);
|
|
|
|
|
}
|
2011-02-14 11:01:31 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<Quote> GetMostRecentQuotes(int limit) {
|
|
|
|
|
return quoteRepository
|
|
|
|
|
.Records
|
|
|
|
|
.OrderByDescending(quote => quote.Created)
|
|
|
|
|
.Take(limit);
|
|
|
|
|
}
|
2011-02-12 23:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|