generated from ricardo/MVCLogin
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using MongoDB.Driver;
|
|
using SumaTube.Infra.MongoDB.Documents.UserPlan;
|
|
|
|
namespace SumaTube.Infra.MongoDB.Repositories.UserPlan
|
|
{
|
|
public class PersonUserRepository
|
|
{
|
|
private readonly IMongoCollection<PersonUserDocument> _collection;
|
|
|
|
public PersonUserRepository(IMongoDatabase database)
|
|
{
|
|
_collection = database.GetCollection<PersonUserDocument>("PersonUsers");
|
|
}
|
|
|
|
public async Task<PersonUserDocument> GetByIdAsync(string id)
|
|
{
|
|
return await _collection.Find(p => p.Id == id).FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<PersonUserDocument>> GetAllAsync()
|
|
{
|
|
return await _collection.Find(_ => true).ToListAsync();
|
|
}
|
|
|
|
public async Task CreateAsync(PersonUserDocument PersonUserDocument)
|
|
{
|
|
await _collection.InsertOneAsync(PersonUserDocument);
|
|
}
|
|
|
|
public async Task UpdateAsync(PersonUserDocument PersonUserDocument)
|
|
{
|
|
await _collection.ReplaceOneAsync(p => p.Id == PersonUserDocument.Id, PersonUserDocument);
|
|
}
|
|
|
|
public async Task DeleteAsync(string id)
|
|
{
|
|
await _collection.DeleteOneAsync(p => p.Id == id);
|
|
}
|
|
}
|
|
} |