vgquotes/Src/VideoGameQuotes.Api/Persistence/UserService.cs

65 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using JetBrains.Annotations;
using Portoa.Persistence;
2011-02-10 04:39:59 +00:00
namespace VideoGameQuotes.Api.Persistence {
public interface IUserService {
User Save(User user);
[CanBeNull]
2011-02-10 04:39:59 +00:00
User FindByUsername(string name);
[CanBeNull]
User FindByIpAddress(string ipAddress);
void Delete(int id);
void Ban(User user);
[CanBeNull]
User FindByUsernameOrIp(string usernameOrIp);
[NotNull]
User FindById(int id);
2011-02-10 04:39:59 +00:00
}
public class UserService : IUserService {
private readonly IUserRepository repository;
public UserService(IUserRepository repository) {
this.repository = repository;
}
[UnitOfWork]
public User Save(User user) {
return repository.Save(user);
}
[UnitOfWork]
public User FindByUsername(string name) {
return repository.FindByUsername(name);
}
[UnitOfWork]
public User FindByIpAddress(string ipAddress) {
return repository.FindByIpAddress(ipAddress);
}
[UnitOfWork]
public void Delete(int id) {
repository.Delete(id);
}
[UnitOfWork]
public void Ban(User user) {
throw new NotImplementedException();
}
[UnitOfWork]
public User FindByUsernameOrIp(string usernameOrIp) {
return repository
.Records
.FirstOrDefault(user => user.Username == usernameOrIp || user.IpAddress == usernameOrIp);
}
[UnitOfWork]
public User FindById(int id) {
return repository.FindById(id);
}
2011-02-10 04:39:59 +00:00
}
}