QlbrcTenantRepository.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Quadarax.Application.QLiberace.Common.Domain;
  2. using Quadarax.Application.QLiberace.Common.Entities.Base;
  3. using Quadarax.Foundation.Core.Data;
  4. using Quadarax.Foundation.Core.Data.Domain;
  5. using Quadarax.Foundation.Core.Data.Interface;
  6. using Quadarax.Foundation.Core.Data.Interface.Domain;
  7. using Quadarax.Foundation.Core.Data.Extensions;
  8. namespace Quadarax.Application.QLiberace.Common.Repositories
  9. {
  10. public abstract class QlbrcTenantRepository<TEntity> :QlbrcRepository<TEntity> where TEntity : QlbrcEntityTenant, new()
  11. {
  12. protected long? TenantId => OperationContext.GetContext<QlbrcContext>().TenantId;
  13. protected QlbrcTenantRepository(IUnitOfWork<IDataDomain> unitOfWork, QlbrcContext operationContext) : base(unitOfWork, operationContext)
  14. {
  15. }
  16. public override IQueryable<TEntity> Query(IPaging paging,bool usingUncommited=false)
  17. {
  18. return base.Query(paging, usingUncommited).Where(x=>Equals(x.TenantId == TenantId));
  19. }
  20. public override TEntity Get(long id)
  21. {
  22. return Query(new Paging()).MultiInclude(DefaultIncludes.ToArray()).FirstOrDefault(x => Equals(x.Id, id) && Equals(x.TenantId,TenantId))!;
  23. }
  24. public override IQueryable<TEntity> Get(IEnumerable<long> ids)
  25. {
  26. return Query(new Paging()).Where(x => ids.Contains(x.Id) && Equals(x.TenantId,TenantId));
  27. }
  28. public override TEntity New()
  29. {
  30. var entity = base.New();
  31. entity.TenantId = TenantId.GetValueOrDefault();
  32. return entity;
  33. }
  34. }
  35. }