Poszukiwacz/Serwer/Serwer.Infrastructure/Repositories/HistoryRepository.cs

32 lines
909 B
C#
Raw Normal View History

2021-01-09 14:44:14 +01:00
using Serwer.Core.Domain;
using Serwer.Core.Repositories;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Repositories
{
public class HistoryRepository: IHistoryRepository
{
private static ISet<UserHistory> _history = new HashSet<UserHistory>();
public async Task AddAsync(User user, string query)
{
var history = _history.FirstOrDefault(x => x.User.Id == user.Id);
if(history == null)
{
history = new UserHistory(user);
}
history.Add(query);
await Task.FromResult(_history.Add(history));
}
public async Task<UserHistory> GetAsync(User user)
{
var history = _history.FirstOrDefault(x => x.User.Id == user.Id);
return await Task.FromResult(history);
}
}
}