Poszukiwacz/Serwer/Serwer.Infrastructure/Repositories/UserRepository.cs
2020-12-06 16:01:38 +01:00

52 lines
1.4 KiB
C#

using Serwer.Core.Domain;
using Serwer.Core.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Repositories
{
public class UserRepository : IUserRepository
{
private static ISet<User> _users = new HashSet<User>();
public async Task AddAsync(User user)
{
await Task.FromResult(_users.Add(user));
}
public async Task<IEnumerable<User>> GetAllAsync()
{
return await Task.FromResult(_users);
}
public async Task<User> GetAsync(Guid id)
{
return await Task.FromResult(_users.SingleOrDefault(x => x.Id == id));
}
public async Task<User> GetAsync(string login)
{
return await Task.FromResult(_users.SingleOrDefault(x => x.Login == login));
}
public async Task RemoveAsync(Guid id)
{
var user = await GetAsync(id);
_users.Remove(user);
}
public async Task UpdateAsync(User user)
{
var dbuser = await GetAsync(user.Id);
dbuser.SetEmail(user.Email);
dbuser.SetLogin(user.Login);
dbuser.SetName(user.Name);
dbuser.SetSurname(user.Surname);
dbuser.SetPassword(user.Password);
}
}
}