59 lines
2.6 KiB
C#
59 lines
2.6 KiB
C#
using DigitalData.Core.Abstractions.Infrastructure;
|
|
using DigitalData.Core.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using WorkFlow.Domain.Entities;
|
|
using WorkFlow.Infrastructure.Contracts;
|
|
|
|
namespace WorkFlow.Infrastructure.Repositories
|
|
{
|
|
public class ProfileObjStateRepository(WFDBContext dbContext) : CRUDRepository<ProfileObjState, int, WFDBContext>(dbContext, dbContext.ProfileObjStates), IProfileObjStateRepository, ICRUDRepository<ProfileObjState, int>
|
|
{
|
|
protected override IQueryable<ProfileObjState> ReadOnly() => base.ReadOnly().Include(pos => pos.Profile).Include(pos => pos.State);
|
|
|
|
protected IQueryable<ProfileObjState> Read(bool isReadonly = false, bool withProfile = true, bool withUser = true, bool withState = true, int? profileId = null, int? userId = null, string? username = null, int? stateId = null, int? objId = null, bool? profileActive = null)
|
|
{
|
|
var query = isReadonly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
|
|
|
|
if (withProfile)
|
|
query = query.Include(pctf => pctf.Profile);
|
|
|
|
if (withUser)
|
|
query = query.Include(pctf => pctf.User);
|
|
|
|
if (withState)
|
|
query = query.Include(pctf => pctf.State);
|
|
|
|
if (profileId is not null)
|
|
query = query.Where(pctf => pctf.ProfileId == profileId);
|
|
|
|
if (userId is not null)
|
|
query = query.Where(pctf => pctf.UserId == userId);
|
|
|
|
if (username is null)
|
|
query = query.Where(pctf => pctf.User!.Username == username);
|
|
|
|
if (stateId is null)
|
|
query = query.Where(pctf => pctf.State!.Id == stateId);
|
|
|
|
if (objId is not null)
|
|
query = query.Where(pctf => pctf.ObjId == objId);
|
|
|
|
if (profileActive is not null)
|
|
query = query.Where(pctf => pctf.Profile!.Active == profileActive);
|
|
|
|
return query;
|
|
}
|
|
|
|
public async Task<IEnumerable<ProfileObjState>> ReadAsync(
|
|
bool isReadonly = true,
|
|
bool withProfile = true, bool withUser = true, bool withState = true,
|
|
int? userId = null, string? username = null,
|
|
int? profileId = null, int? objId = null, bool? profileActive = null)
|
|
=> await Read(
|
|
isReadonly: isReadonly,
|
|
withProfile: withProfile, withUser: withUser, withState: withState,
|
|
userId: userId, username: username,
|
|
profileId: profileId, objId: objId, profileActive: profileActive)
|
|
.ToListAsync();
|
|
}
|
|
} |