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 GetFlaggedQuotes(); User GetUser(int id); IEnumerable GetAllUsers(); } public class AdministrationService : IAdministrationService { private readonly IRepository userRepository; private readonly IRepository quoteRepository; public AdministrationService(IRepository userRepository, IRepository quoteRepository) { this.userRepository = userRepository; this.quoteRepository = quoteRepository; } [UnitOfWork] public User SaveUser(User user) { return userRepository.Save(user); } [UnitOfWork] public IEnumerable GetFlaggedQuotes() { return quoteRepository.Records .Where(quote => quote.Flags.Any()) .ToArray() .OrderByDescending(quote => quote.Flags.Count()); } [UnitOfWork] public User GetUser(int id) { return userRepository.FindById(id); } [UnitOfWork] public IEnumerable GetAllUsers() { return userRepository.Records; } } }