| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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<TEntity> :QlbrcRepository<TEntity> where TEntity : QlbrcEntityTenant, new()
- {
- protected long? TenantId => OperationContext.GetContext<QlbrcContext>().TenantId;
- protected QlbrcTenantRepository(IUnitOfWork<IDataDomain> unitOfWork, QlbrcContext operationContext) : base(unitOfWork, operationContext)
- {
- }
- public override IQueryable<TEntity> 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<TEntity> Get(IEnumerable<long> 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;
- }
- }
- }
|