32 lines
909 B
C#
32 lines
909 B
C#
|
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);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|