shopping-assistant-api/ShoppingAssistantApi.Persistance/Repositories/RolesRepository.cs

23 lines
982 B
C#

using MongoDB.Bson;
using MongoDB.Driver;
using ShoppingAssistantApi.Application.IRepositories;
using ShoppingAssistantApi.Domain.Entities;
using ShoppingAssistantApi.Persistance.Database;
using System.Linq.Expressions;
namespace ShoppingAssistantApi.Persistance.Repositories;
public class RolesRepository : BaseRepository<Role>, IRolesRepository
{
public RolesRepository(MongoDbContext db) : base(db, "Roles") { }
public async Task<Role> GetRoleAsync(ObjectId id, CancellationToken cancellationToken)
{
return await (await this._collection.FindAsync(x => x.Id == id && x.IsDeleted == false)).FirstOrDefaultAsync(cancellationToken);
}
public async Task<Role> GetRoleAsync(Expression<Func<Role, bool>> predicate, CancellationToken cancellationToken)
{
return await (await this._collection.FindAsync(Builders<Role>.Filter.Where(predicate) & Builders<Role>.Filter.Where(x => !x.IsDeleted))).FirstOrDefaultAsync(cancellationToken);
}
}