2011-02-18 01:46:02 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Portoa.Persistence;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web.Services {
|
|
|
|
|
public interface IAdministrationService {
|
|
|
|
|
User SaveUser(User user);
|
2011-02-18 01:46:02 +00:00
|
|
|
|
IEnumerable<Quote> GetFlaggedQuotes();
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AdministrationService : IAdministrationService {
|
2011-02-18 01:46:02 +00:00
|
|
|
|
private readonly IRepository<User> userRepository;
|
|
|
|
|
private readonly IRepository<Quote> quoteRepository;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-18 01:46:02 +00:00
|
|
|
|
public AdministrationService(IRepository<User> userRepository, IRepository<Quote> quoteRepository) {
|
2011-02-17 20:55:47 +00:00
|
|
|
|
this.userRepository = userRepository;
|
2011-02-18 01:46:02 +00:00
|
|
|
|
this.quoteRepository = quoteRepository;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public User SaveUser(User user) {
|
|
|
|
|
return userRepository.Save(user);
|
|
|
|
|
}
|
2011-02-18 01:46:02 +00:00
|
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
public IEnumerable<Quote> GetFlaggedQuotes() {
|
|
|
|
|
return quoteRepository.Records
|
|
|
|
|
.Where(quote => quote.Flags.Any())
|
|
|
|
|
.ToArray()
|
|
|
|
|
.OrderByDescending(quote => quote.Flags.Count());
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|