65 lines
1.4 KiB
C#
65 lines
1.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using JetBrains.Annotations;
|
|
using Portoa.Persistence;
|
|
|
|
namespace VideoGameQuotes.Api.Persistence {
|
|
public interface IUserService {
|
|
User Save(User user);
|
|
[CanBeNull]
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |