using Quadarax.Application.QLiberace.Common.Domain; using Quadarax.Application.QLiberace.Common.Entities.Base; using Quadarax.Foundation.Core.Data; using Quadarax.Foundation.Core.Data.Domain; using Quadarax.Foundation.Core.Data.Interface; using Quadarax.Foundation.Core.Data.Interface.Domain; using Quadarax.Foundation.Core.Data.Extensions; namespace Quadarax.Application.QLiberace.Common.Repositories { public abstract class QlbrcTenantRepository :QlbrcRepository where TEntity : QlbrcEntityTenant, new() { protected long? TenantId => OperationContext.GetContext().TenantId; protected QlbrcTenantRepository(IUnitOfWork unitOfWork, QlbrcContext operationContext) : base(unitOfWork, operationContext) { } public override IQueryable Query(IPaging paging,bool usingUncommited=false) { return base.Query(paging, usingUncommited).Where(x=>Equals(x.TenantId == TenantId)); } public override TEntity Get(long id) { return Query(new Paging()).MultiInclude(DefaultIncludes.ToArray()).FirstOrDefault(x => Equals(x.Id, id) && Equals(x.TenantId,TenantId))!; } public override IQueryable Get(IEnumerable ids) { return Query(new Paging()).Where(x => ids.Contains(x.Id) && Equals(x.TenantId,TenantId)); } public override TEntity New() { var entity = base.New(); entity.TenantId = TenantId.GetValueOrDefault(); return entity; } } }