using System.Diagnostics; 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.Extensions; using Quadarax.Foundation.Core.Data.Interface; using Quadarax.Foundation.Core.Data.Interface.Domain; namespace Quadarax.Application.QLiberace.Common.Repositories { public abstract class QlbrcTenantTrackedRepository :QlbrcTrackedRepository where TEntity : QlbrcEntityTenant, new() { protected long? TenantId => OperationContext.GetContext().TenantId; protected QlbrcTenantTrackedRepository(IUnitOfWork unitOfWork, QlbrcContext operationContext) : base(unitOfWork, operationContext) { } public override IQueryable Query(IPaging paging,bool usingUncommited=false) { var result = base.Query(paging, usingUncommited).Where(x => Equals(x.TenantId ,TenantId)); #if DEBUG Debug.WriteLine($"Repo '{GetType().Name}' Query returns {result.Count()} rows."); #endif return result; } 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; } } }