diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 72c9a0d10..15b935e07 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -562,6 +562,107 @@ SystemAnonymizationService + + + 子类 + + + + + 配置 基础逻辑信息 + + + + + 配置流程 + + + + + 配置加急信息 + + + + + 用户 签名某个文档 Dto + + + + + 功能模块 + + + + + 盲态访视名 + + + + + 项目iD + + + + + 中心 + + + + + 受试者 + + + + + 访视 + + + + + 操作类型 + + + + + 子类 + + + + + 修改原因 + + + + + 是否有签名 + + + + + 通用逻辑封装 + + 方法参数 + 添加稽查 + 用户签名 + 委托 + + + + + 映射 SiteId SubjectId SubjectVisitId TrialId 最开始没有 需要特殊处理 + + + + + + 验证用户签名信息 /// + + + 添加签名记录 /// + + + 添加稽查记录( 有的会签名,有的不会签名) /// + 项目外部人员 录入流程相关 @@ -816,6 +917,13 @@ Setting页面 Site批量添加 + + + 项目site 编辑接口 New 可以设置为启用不启用 不启用 不会验证Code 重复 + + + + 编辑项目中Site 基本信息 @@ -858,212 +966,6 @@ - - 指定资源Id,渲染Dicom检查的Jpeg预览图像 - Dicom检查的Id - - - - 获取某个检查的关联检查列表(该受试者在这个想项目下的所有检查) - 点击检查检查列表中的一个检查获取对应的序列列表(调用之前的接口:/series/list/,根据StudyId,获取访视的序列列表) - - - - - 指定资源Id,获取Dicom检查信息 - Dicom检查的Id - - - - 批量验证 检查是否可以上传 并告知原因 - - - - - SystemAnonymizationService - - - - - 子类 - - - - - 配置 基础逻辑信息 - - - - - 配置流程 - - - - - 配置加急信息 - - - - - 用户 签名某个文档 Dto - - - - - 功能模块 - - - - - 盲态访视名 - - - - - 项目iD - - - - - 中心 - - - - - 受试者 - - - - - 访视 - - - - - 操作类型 - - - - - 子类 - - - - - 修改原因 - - - - - 是否有签名 - - - - - 通用逻辑封装 - - 方法参数 - 添加稽查 - 用户签名 - 委托 - - - - - 映射 SiteId SubjectId SubjectVisitId TrialId 最开始没有 需要特殊处理 - - - - - - 验证用户签名信息 /// - - - 添加签名记录 /// - - - 添加稽查记录( 有的会签名,有的不会签名) /// - - - - 项目外部人员 录入流程相关 - - - - - 验证 在系统中是否存在该类型的账户 返回true 表示 不存在 可以添加和更新|存在但是信息一致,false 需要提示不一致项(前端 可以直接用我返回的错误信息,或者根据返回的用户信息实体,自己设置格式显示) - - - - - - - 添加和更新接口 已验证邮箱和账户类型不允许添加重复项 - - - - - - - 勾选用户 批量发送邮件 - - - - - - 不带Token 访问 用户选择 参与 不参与 Id: TrialExternalUserId - - - - - - - 不带Token 访问 Site调研用户 加入项目 Id: TrialSiteSurveyUserId - - - - - - - 不带Token 访问 页面获取项目基本信息 和参与情况 (已经确认了 就不允许再次确认) Id: TrialExternalUserId/TrialSiteSurveyUserId - - - - - - - 加入项目 - - - - - - - - TrialUserPreparation Service - - - - - 项目下 人员邀请 加入列表 - - - - - - - 不带Token访问 加入项目 记录 同意与否 - - - - - - - 用户加入项目 - - - - CRC 访视上传列表 diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs index 66ae16131..414662d52 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs @@ -1,6 +1,7 @@ using System; using IRaCIS.Core.Infrastructure.Extention; using IRaCIS.Core.Domain.Share; +using System.ComponentModel.DataAnnotations; namespace IRaCIS.Core.Application.Contracts.DTO { @@ -9,10 +10,16 @@ namespace IRaCIS.Core.Application.Contracts.DTO public class SiteCrcQueryDTO : PageInput { public Guid TrialId { get; set; } = Guid.Empty; - public string UserRealName { get; set; } = String.Empty; public string SiteName { get; set; } = String.Empty; public string TrialSiteAliasName { get; set; } = String.Empty; + public bool? IsDeleted { get; set; } + + public string TrialSiteCode { get; set; } = String.Empty; + + public string UserKeyInfo { get; set; } = String.Empty; + + } public class TrialSiteCommand @@ -22,9 +29,26 @@ namespace IRaCIS.Core.Application.Contracts.DTO public string SiteName { get; set; } -} + } -public class AssginSiteCRCCommand + public class EditTrialSiteCommand + { + //Guid id, Guid trialId, string trialSiteCode, string? trialSiteAliasName + + [NotDefault] + public Guid TrialId { get; set; } + + public Guid Id { get; set; } + + public string TrialSiteAliasName { get; set; } = String.Empty; + + public string TrialSiteCode { get; set; } = String.Empty; + + public bool IsDeleted { get; set; } + + } + + public class AssginSiteCRCCommand { public Guid TrialId { get; set; } public Guid SiteId { get; set; } @@ -34,7 +58,7 @@ public class AssginSiteCRCCommand } - public class AssginSiteCRCListDTO:AssginSiteCRCCommand + public class AssginSiteCRCListDTO : AssginSiteCRCCommand { public Guid UserTypeId { get; set; } public string UserType { get; set; } = String.Empty; @@ -58,7 +82,7 @@ public class AssginSiteCRCCommand public class TrialSiteScreeningDTO { - public Guid Id { get; set; } + public Guid Id { get; set; } public string SiteName { get; set; } = String.Empty; public string SiteCode { get; set; } = String.Empty; public string City { get; set; } = String.Empty; @@ -66,7 +90,7 @@ public class AssginSiteCRCCommand public Guid HospitalId { get; set; } = Guid.Empty; - public string HospitalName { get; set; } = String.Empty; + public string HospitalName { get; set; } = String.Empty; public bool IsSelect { get; set; } } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index c21ab978f..9e6ff4b9e 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -105,6 +105,8 @@ namespace IRaCIS.Application.Contracts public string TrialSiteCode { get; set; } = String.Empty; public string TrialSiteAliasName { get; set; } = String.Empty; + + public bool IsDeleted { get; set; } public DateTime UpdateTime { get; set; } public string Site { get; set; } = String.Empty; diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index 894a50fc8..cfc74afad 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -63,32 +63,7 @@ namespace IRaCIS.Application.Services param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc); - //from userTrial in.Where(userTrialLambda) - // join user in _userRepository.Where(userLambda) on userTrial.UserId equals user.Id - // // 判断site下面的用户是否已经选择 - // join userId in _userTrialSiteRepository.Where(t => t.TrialId == param.TrialId && t.SiteId == param.SiteId).Select(t => t.UserId).Distinct() on user.Id equals userId into cc - // from userId in cc.DefaultIfEmpty() - // select new AssginSiteCRCListDTO() - // { - // //Id = userTrial.Id, - // SiteId = param.SiteId, - // UserId = userTrial.UserId, - // UserRealName = user.LastName + " / " + user.FirstName, - // UserName = user.UserName, - - // TrialId = userTrial.TrialId, - // UserTypeId = userTrial.UserTypeId, - // UserTypeEnum= user.UserTypeEnum, - - // //OrganizationTypeId = userTrial.OrganizationTypeId, - // //OrganizationType = userTrial.OrganizationType, - // //OrganizationId = userTrial.OrganizationId, - // OrganizationName = user.OrganizationName, - // UpdateTime = userTrial.UpdateTime, - // UserType = userTrial.UserType, - - // IsSelect = userId!=null, - // }; + } @@ -114,34 +89,7 @@ namespace IRaCIS.Application.Services - //IQueryable userQueryable = from user in _userRepository.Where(userLambda) - // join userType in _userTypeRoleRepository.AsQueryable() on user.UserTypeId equals userType.Id - // //下面左连接 判断是否已经选择了 - // join userId in _userTrialRepository.Where(t => t.TrialId == trialUserQuery.TrialId).Select(t=>t.UserId).Distinct() on user.Id equals userId into cc - // from userId in cc.DefaultIfEmpty() - // select new TrialUserScreeningDTO() - // { - // TrialId = trialUserQuery.TrialId, - // UserId = user.Id, - // UserRealName = user.LastName + " / " + user.FirstName, - // UserName = user.UserName, - // Sex = user.Sex, - - // Phone = user.Phone, - // EMail = user.EMail, - // UserTypeId = user.UserTypeId, - - // OrganizationName = user.OrganizationName, - // UserTypeEnum=user.UserTypeEnum, - // //OrganizationTypeId = user.OrganizationTypeId, - // //OrganizationType = user.OrganizationType, - // //OrganizationId = user.OrganizationId, - // DepartmentName = user.DepartmentName, - // PositionName = user.PositionName, - - // IsSelect = userId != null - // UserType = userType.UserTypeShortName, - // }; + diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs index 0e9f8f9df..9df635af4 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs @@ -25,77 +25,16 @@ namespace IRaCIS.Core.Application.Services public async Task> GetSiteCRCList(SiteCrcQueryDTO param) { - var siteStatQuery = _trialSiteRepository.Where(t => t.TrialId == param.TrialId) + var siteStatQuery = _trialSiteRepository.Where(t => t.TrialId == param.TrialId, ignoreQueryFilters: true) .WhereIf(!string.IsNullOrWhiteSpace(param.SiteName), t => t.Site.SiteName.Contains(param.SiteName)) + .WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteAliasName), t => t.TrialSiteAliasName.Contains(param.TrialSiteAliasName)) + .WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteAliasName.Contains(param.TrialSiteCode)) .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator, t => t.CRCUserList.Any(k => k.UserId == _userInfo.Id)) - .WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserRealName))) + .WhereIf(!string.IsNullOrWhiteSpace(param.UserKeyInfo), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserKeyInfo) + || k.User.UserName.Contains(param.UserKeyInfo) || k.User.EMail.Contains(param.UserKeyInfo))) .ProjectTo(_mapper.ConfigurationProvider); - #region 统计 废弃 - //= from trialSite in - // join site in _siteRepository.Where() on trialSite.SiteId equals site.Id - // join userTrialStat in _userTrialSiteRepository - // .Where(t => t.TrialId == param.TrialId).GroupBy(u => u.SiteId) - // .Select(g => new { SiteId = g.Key, UserCount = g.Count() }) on site.Id equals userTrialStat.SiteId into kk - // from userTrialStat in kk.DefaultIfEmpty() - - // join subjectStat in _subjectRepository.Where(t => t.TrialId == param.TrialId).GroupBy(u => u.SiteId) - // .Select(g => new { SiteId = g.Key, SubjectCount = g.Count() }) on site.Id equals subjectStat - // .SiteId - // into ST - // from subjectStatItem in ST.DefaultIfEmpty() - - // ////加入 Visit统计 通过site下的受试者过滤visit 加入siteId 后修改 不用通过site下的用户过滤 - // //join subjectVisitStat in _subjectVisitRepository.Find(t=>t.TrialId==param.TrialId).GroupBy(t => t.SiteId).Select(g => new { SiteId = g.Key, VisitCount = g.Count() }) on site.Id equals subjectVisitStat.SiteId into SSV - // //from subjectVisitStatItem in SSV.DefaultIfEmpty() - - // //join subjectVisitStat2 in _subjectVisitRepository.Find(t => t.TrialId == param.TrialId&&t.VisitExecuted).GroupBy(t => t.SiteId).Select(g => new { SiteId = g.Key, VisitCount = g.Count() }) on site.Id equals subjectVisitStat2.SiteId into SSV2 - // //from subjectVisitStatItem2 in SSV2.DefaultIfEmpty() - - // join studyStat in _studyRepository.Where(t => t.TrialId == param.TrialId /*&& t.Status != (int)StudyStatus.Abandon*/).GroupBy(u => u.SiteId).Select(g => new { SiteId = g.Key, StudyCount = g.Count() }) on site.Id equals studyStat.SiteId into STT - // from studyStatItem in STT.DefaultIfEmpty() - // select new SiteStatDTO() - // { - // SiteId = site.Id, - // Site = site.SiteName, - // City = site.City, - // Country = site.Country, - - // TrialSiteCode = trialSite.TrialSiteCode, - - - // //VisitCount = subjectVisitStatItem2.VisitCount, - // //PlanVisitCount = subjectVisitStatItem.VisitCount, - - - // StudyCount = studyStatItem.StudyCount, - // UserCount = userTrialStat.UserCount, - // SubjectCount = subjectStatItem.SubjectCount, - - // UserList = trialSite.CRCUserList.Select(t => new UserTrialDTO() - // { - // Id = t.Id, - // SiteId = t.SiteId, - - // UserId = t.UserId, - // UserRealName = t.UserRealName, - - // TrialId = t.TrialId, - // UserTypeId = t.UserTypeId, - // UserType = t.UserType, - // //OrganizationTypeId = userTrial.OrganizationTypeId, - // //OrganizationType = userTrial.OrganizationType, - // //OrganizationId = userTrial.OrganizationId, - // OrganizationName = t.User.OrganizationName, - // UserName = t.User.UserName, - // Phone = t.User.Phone, - // UpdateTime = t.UpdateTime, - // }).ToList() - // }; - #endregion - - return await siteStatQuery.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "SiteCode" : param.SortField, param.Asc); @@ -108,63 +47,16 @@ namespace IRaCIS.Core.Application.Services public async Task> GetSiteCRCSimpleList(SiteCrcQueryDTO param) { - var siteStatQuery = _trialSiteRepository.Where(t => t.TrialId == param.TrialId) + var siteStatQuery = _trialSiteRepository.Where(t => t.TrialId == param.TrialId).IgnoreQueryFilters() .WhereIf(!string.IsNullOrWhiteSpace(param.SiteName), t => t.Site.SiteName.Contains(param.SiteName)) .WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteAliasName), t => t.TrialSiteAliasName.Contains(param.TrialSiteAliasName)) + .WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteAliasName.Contains(param.TrialSiteCode)) .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator, t => t.CRCUserList.Any(k => k.UserId == _userInfo.Id)) - .WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserRealName))) + .WhereIf(!string.IsNullOrWhiteSpace(param.UserKeyInfo), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserKeyInfo) + || k.User.UserName.Contains(param.UserKeyInfo) || k.User.EMail.Contains(param.UserKeyInfo))) .ProjectTo(_mapper.ConfigurationProvider); - #region 废弃 - //IQueryable siteStatQuery = from trialSite in _trialSiteRepository.Where(t => t.TrialId == param.TrialId) - // join site in _siteRepository.AsQueryable() on trialSite.SiteId equals site.Id - // join hospital in _hospitalRepository.AsQueryable() on site.HospitalId equals hospital.Id - // join userTrialStat in _userTrialSiteRepository - // .Where(t => t.TrialId == param.TrialId).GroupBy(u => u.SiteId) - // .Select(g => new { SiteId = g.Key, UserCount = g.Count() }) on site.Id equals userTrialStat.SiteId into kk - // from userTrialStat in kk.DefaultIfEmpty() - // select new SiteStatSimpleDTO() - // { - // Id = trialSite.Id, - // SiteId = site.Id, - // Site = site.SiteName, - // SiteCode = site.SiteCode, - // TrialSiteCode = trialSite.TrialSiteCode, - // Hospital = hospital.HospitalName, - // DirectorName = site.DirectorName, - // DirectorPhone = site.DirectorPhone, - // ContactName = site.ContactName, - // ContactPhone = site.ContactPhone, - // City = site.City, - // Country = site.Country, - // UpdateTime = trialSite.UpdateTime, - // UserCount = userTrialStat.UserCount, - - // UserList = trialSite.CRCUserList.Select(t => new UserTrialDTO() - // { - // Id = t.Id, - // SiteId = t.SiteId, - - // UserId = t.UserId, - // UserRealName = t.UserRealName, - - // TrialId = t.TrialId, - // UserTypeId = t.UserTypeId, - // UserType = t.UserType, - // //OrganizationTypeId = userTrial.OrganizationTypeId, - // //OrganizationType = userTrial.OrganizationType, - // //OrganizationId = userTrial.OrganizationId, - // OrganizationName = t.User.OrganizationName, - // UserName = t.User.UserName, - // Phone = t.User.Phone, - // UpdateTime = t.UpdateTime, - // }).ToList() - // }; - - - #endregion - var result = await siteStatQuery.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "Site" : param.SortField, param.Asc); @@ -175,12 +67,12 @@ namespace IRaCIS.Core.Application.Services /// 获取某一Site下面的负责的CRC列表 [HttpGet, Route("{trialId:guid}/{siteId:guid}")] - public async Task> GetTrialSiteCRCList(Guid trialId,Guid siteId) + public async Task> GetTrialSiteCRCList(Guid trialId, Guid siteId) { - var query = _repository.Where(t => t.TrialId == trialId && t.SiteId==siteId).IgnoreQueryFilters() + var query = _repository.Where(t => t.TrialId == trialId && t.SiteId == siteId).IgnoreQueryFilters() .ProjectTo(_mapper.ConfigurationProvider); - return await query.ToListAsync(); + return await query.ToListAsync(); } @@ -220,21 +112,76 @@ namespace IRaCIS.Core.Application.Services } - /// - /// 编辑项目中Site 基本信息 - /// - /// - /// - /// - /// - /// + + + /// + /// 项目site 编辑接口 New 可以设置为启用不启用 不启用 不会验证Code 重复 + /// + /// + /// + [HttpPut] + public async Task EditTrialSite(EditTrialSiteCommand editTrialSiteCommand) + { + + var dbEntity = await _trialSiteRepository.FirstOrDefaultAsync(t => t.Id == editTrialSiteCommand.Id, true); + + if (dbEntity == null) return Null404NotFound(dbEntity); + + var trialId = dbEntity.TrialId; + var siteId = dbEntity.SiteId; + + if (editTrialSiteCommand.IsDeleted) + { + + //if (await _repository.AnyAsync(t => t.TrialId == trialId && t.SiteId == siteId)) + //{ + // return ResponseOutput.NotOk("The site has been associated with CRC, and couldn't be deleted."); + //} + + if (await _repository.AnyAsync(t => t.SiteId == siteId && t.TrialId == trialId)) + { + return ResponseOutput.NotOk("The subjects has been added to this site, and couldn't be deleted."); + } + + //if (await _repository.AnyAsync(t => t.SiteId == siteId && t.TrialId == trialId)) + //{ + // return ResponseOutput.NotOk("The site has been uploaded study, and couldn't be deleted."); + //} + } + else + { + if (await _trialSiteRepository.AnyAsync(t => t.Id != editTrialSiteCommand.Id && t.TrialSiteCode == editTrialSiteCommand.TrialSiteCode && t.TrialId == editTrialSiteCommand.TrialId)) + { + return ResponseOutput.NotOk("Code is not allowed to be repeated"); + } + } + + + _mapper.Map(editTrialSiteCommand, dbEntity); + + await _trialSiteRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + + } + + + /// + /// 编辑项目中Site 基本信息 + /// + /// + /// + /// + /// + /// [UnitOfWork] [HttpPost("{trialId:guid}/{id:guid}/{trialSiteCode}/{trialSiteAliasName?}")] [TypeFilter(typeof(TrialResourceFilter))] + [Obsolete] public async Task EditTrialSite(Guid id, Guid trialId, string trialSiteCode, string? trialSiteAliasName) { - if (await _trialSiteRepository.AnyAsync(t => t.Id != id && t.TrialSiteCode == trialSiteCode && t.TrialId == trialId)) + if (await _trialSiteRepository.AnyAsync(t => t.Id != id && t.TrialSiteCode == trialSiteCode && t.TrialId == trialId && t.IsDeleted == false, true)) { return ResponseOutput.NotOk("Code is not allowed to be repeated"); } @@ -250,6 +197,7 @@ namespace IRaCIS.Core.Application.Services [HttpDelete("{id:guid}/{trialId:guid}")] [TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrialSite)] [TypeFilter(typeof(TrialResourceFilter))] + [Obsolete] public async Task DeleteTrialSite(Guid id) { var relation = await _trialSiteRepository.FirstOrDefaultAsync(t => t.Id == id); @@ -298,9 +246,9 @@ namespace IRaCIS.Core.Application.Services //[TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrialSiteCRC)] [TypeFilter(typeof(TrialResourceFilter))] - public async Task DeleteSiteCRC(Guid id, bool isDelete ) + public async Task DeleteSiteCRC(Guid id, bool isDelete) { - var isSuccess = await _repository.UpdateFromQueryAsync(u => u.Id == id,u=>new TrialSiteUser() + var isSuccess = await _repository.UpdateFromQueryAsync(u => u.Id == id, u => new TrialSiteUser() { IsDeleted = isDelete, RemoveTime = isDelete ? DateTime.Now : null }); return ResponseOutput.Result(isSuccess); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 1fec3f22d..fd8480485 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -22,9 +22,10 @@ namespace IRaCIS.Core.Infra.EFCore EntityEntry Entry(TEntity t); - Task FirstOrDefaultAsync(Expression> exp = null); - Task AnyAsync(Expression> exp); - Task CountAsync(Expression> whereLambda = null); + Task FirstOrDefaultAsync(Expression> exp = null, bool ignoreQueryFilters = false); + + Task AnyAsync(Expression> exp,bool ignoreQueryFilters=false); + Task CountAsync(Expression> whereLambda = null, bool ignoreQueryFilters = false); ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); Task AddRangeAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IQueryRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/IQueryRepository.cs index 0aa3a71fd..fcbe2ddee 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IQueryRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IQueryRepository.cs @@ -24,8 +24,8 @@ namespace IRaCIS.Core.Infra.EFCore public interface IQueryRepository : IQueryRepository where TEntity : Entity { TEntity ImageFind(Guid id, Type type); - IQueryable Where(Expression> exp = null, bool isTraking = false); - IQueryable AsQueryable(); + IQueryable Where(Expression> exp = null, bool isTraking = false, bool ignoreQueryFilters = false); + IQueryable AsQueryable( bool ignoreQueryFilters = false); IQueryable WhereIf(bool condition, Expression> filter); IQueryable ProjectTo(IConfigurationProvider configuration, params Expression>[] membersToExpand); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index a09f1fdd6..9c0d98310 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -113,10 +113,18 @@ namespace IRaCIS.Core.Infra.EFCore return await _dbContext.FindAsync(keyValues); } - public async Task FirstOrDefaultAsync(Expression> exp = null) + public async Task FirstOrDefaultAsync(Expression> exp = null, bool ignoreQueryFilters = false) { - if (exp == null) return await _dbSet.FirstOrDefaultAsync().ConfigureAwait(false); - return await _dbSet.FirstOrDefaultAsync(exp).ConfigureAwait(false); + + var query = _dbSet.AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + if (exp == null) + return await query.FirstOrDefaultAsync().ConfigureAwait(false); + return await query.FirstOrDefaultAsync(exp).ConfigureAwait(false); } public async ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) @@ -205,14 +213,28 @@ namespace IRaCIS.Core.Infra.EFCore } } - public async Task AnyAsync(Expression> exp) + public async Task AnyAsync(Expression> exp, bool ignoreQueryFilters = false) { - return await _dbSet.AsNoTracking().AnyAsync(exp); + var query = _dbSet.AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + return await query.AsNoTracking().AnyAsync(exp); } - public async Task CountAsync(Expression> whereLambda = null) + public async Task CountAsync(Expression> whereLambda = null, bool ignoreQueryFilters = false) { - return whereLambda == null ? await _dbSet.AsNoTracking().CountAsync() : await _dbSet.AsNoTracking().CountAsync(whereLambda); + var query = _dbSet.AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + return whereLambda == null ? await query.AsNoTracking().CountAsync() : await query.AsNoTracking().CountAsync(whereLambda); } // Z.EntityFramework.Plus.EFCore @@ -251,9 +273,16 @@ namespace IRaCIS.Core.Infra.EFCore } - public IQueryable AsQueryable() + public IQueryable AsQueryable( bool ignoreQueryFilters = false) { - return _dbSet.AsNoTracking(); + var query = _dbSet.AsQueryable(); + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + return query.AsNoTracking(); } public IQueryable Select(Expression> selector) @@ -266,7 +295,7 @@ namespace IRaCIS.Core.Infra.EFCore return condition ? _dbSet.AsNoTracking().Where(filter) : _dbSet.AsNoTracking(); } - public IQueryable Where(Expression> exp = null, bool isTraking = false) + public IQueryable Where(Expression> exp = null, bool isTraking = false,bool ignoreQueryFilters = false) { IQueryable query = _dbSet; @@ -275,6 +304,11 @@ namespace IRaCIS.Core.Infra.EFCore query = query.AsNoTracking(); } + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + if (exp != null) { query = query.Where(exp);