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

58 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using Portoa.Persistence;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Services {
public interface IAdministrationService {
User SaveUser(User user);
IEnumerable<Quote> GetFlaggedQuotes();
2011-02-19 23:15:36 +00:00
User GetUser(int id);
IEnumerable<User> GetAllUsers();
IEnumerable<User> GetPagedUsers(int start, int end);
}
public class AdministrationService : IAdministrationService {
private readonly IRepository<User> userRepository;
private readonly IRepository<Quote> quoteRepository;
public AdministrationService(IRepository<User> userRepository, IRepository<Quote> quoteRepository) {
this.userRepository = userRepository;
this.quoteRepository = quoteRepository;
}
[UnitOfWork]
public User SaveUser(User user) {
return userRepository.Save(user);
}
[UnitOfWork]
public IEnumerable<Quote> GetFlaggedQuotes() {
return quoteRepository.Records
.Where(quote => quote.Flags.Any())
.ToArray()
.OrderByDescending(quote => quote.Flags.Count());
}
2011-02-19 23:15:36 +00:00
[UnitOfWork]
public User GetUser(int id) {
return userRepository.FindById(id);
}
[UnitOfWork]
public IEnumerable<User> GetAllUsers() {
return userRepository.Records;
}
[UnitOfWork]
public IEnumerable<User> GetPagedUsers(int start, int end) {
return userRepository
.Records
.OrderBy(user => user.Username)
.ThenBy(user => user.IpAddress)
.Skip(start - 1)
.Take(end - start + 1);
}
}
}