public DTO.SearchResult Search(bool isRKAdmin, Guid clientId, DTO.SearchFilterRestriction filter) { if (!isRKAdmin) { var appStore = applicationStoreRepository.GetByClientId(clientId); if (filter.StoreCode.IsEmpty()) { filter.StoreCode = appStore.StoreCode; } else if (appStore.StoreCode != filter.StoreCode) { throw new ArgumentException("Usuário não possui permissão para realizar essa operação"); } } var result = restrictionRepository.Search(filter); var restrictions = result.Results.Select(r => r.GetResult()); return(new DTO.SearchResult(restrictions).SetResult(result)); }
public VO.SearchResult <Restriction> Search(DTO.SearchFilterRestriction filter) { var result = Collection.Include(x => x.Role).AsQueryable(); if (!filter?.StoreCode.IsEmpty() ?? false) { result = result.Where(x => x.Role.StoreCode == filter.StoreCode); } if (filter?.RoleCode.HasValue ?? false) { result = result.Where(x => x.Role.Code == filter.RoleCode); } result = result.OrderBy(x => x.SaveDate); var count = result.Count(); result = result.Skip(filter.Skip.Value * filter.Take.Value); result = result.Take(filter.Take.Value); return(new VO.SearchResult <Restriction>(result.ToList(), filter, count)); }