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 QlbrcTenantCodeTrackedRepository : QlbrcTrackedRepository where TEntity : QlbrcEntityTenantCode, new() { protected string? TenantCode => OperationContext.GetContext().TenantCode; protected QlbrcTenantCodeTrackedRepository(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.TenantCode ,TenantCode)); #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.TenantCode,TenantCode))!; } public override IQueryable Get(IEnumerable ids) { return Query(new Paging()).Where(x => ids.Contains(x.Id) && Equals(x.TenantCode,TenantCode)); } public override TEntity New() { var entity = base.New(); entity.TenantCode = TenantCode!; return entity; } } }