33 lines
870 B
C#
33 lines
870 B
C#
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using JetBrains.Annotations;
|
|||
|
using Portoa.Persistence;
|
|||
|
using VideoGameQuotes.Api;
|
|||
|
|
|||
|
namespace VideoGameQuotes.Web.Services {
|
|||
|
public interface IGameService {
|
|||
|
[CanBeNull]
|
|||
|
Game FindByNameAndSystems(string name, IEnumerable<int> systemIds);
|
|||
|
Game Save(Game game);
|
|||
|
}
|
|||
|
|
|||
|
public class GameService : IGameService {
|
|||
|
private readonly IRepository<Game> repository;
|
|||
|
|
|||
|
public GameService(IRepository<Game> repository) {
|
|||
|
this.repository = repository;
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Game FindByNameAndSystems(string name, IEnumerable<int> systemIds) {
|
|||
|
return repository
|
|||
|
.Records
|
|||
|
.FirstOrDefault(game => game.Name == name && game.Systems.Any(system => systemIds.Contains(system.Id)));
|
|||
|
}
|
|||
|
|
|||
|
[UnitOfWork]
|
|||
|
public Game Save(Game game) {
|
|||
|
return repository.Save(game);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|