public async Task <PagedResultDto <ProjectDto> > GetProjects(BasePagedAndSortedResultRequestDto filter) { PagedResultDto <ProjectDto> result; // 默认开启租户过滤,所以不在展示 using (DataFilter.Enable <ISoftDelete>()) { var target = (await ProjectRepository.GetListAsync()).WhereIf(!filter.Filter.IsNullOrWhiteSpace(), t => t.Name.Contains(filter.Filter)); // 排序 target = !string.IsNullOrEmpty(filter.Sorting) ? target.OrderBy(c => filter.Sorting) : target.OrderByDescending(t => t.CreationTime); var count = target.Count(); var projectList = target.Skip(filter.SkipCount).Take(filter.MaxResultCount).ToList(); result = new PagedResultDto <ProjectDto>(count, ObjectMapper.Map <IList <Projects.Project>, List <ProjectDto> >(projectList)); return(result); } }
public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { //Soft delete is enabled by default var people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); using (_dataFilter.Disable <ISoftDelete>()) { //Soft delete is disabled people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); using (_dataFilter.Enable <ISoftDelete>()) { //Soft delete is enabled again people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } //Soft delete is disabled (restored previous state) people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); } //Soft delete is enabled (restored previous state) people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); }
public async Task Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { await WithUnitOfWorkAsync(() => { //Soft delete is enabled by default var people = PersonRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); using (DataFilter.Disable <ISoftDelete>()) { //Soft delete is disabled people = PersonRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); using (DataFilter.Enable <ISoftDelete>()) { //Soft delete is enabled again people = PersonRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } //Soft delete is disabled (restored previous state) people = PersonRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); } //Soft delete is enabled (restored previous state) people = PersonRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); return(Task.CompletedTask); }).ConfigureAwait(false); }