예제 #1
0
        private IQueryable <PlaqueToContractor> GetFilteredQuery(GetPlaqueToContractorInput input)
        {
            long tempSearch = 0;

            try
            {
                tempSearch = Convert.ToInt64(input.Filter);
            }
            catch (Exception e)
            {
            }
            var query = QueryableExtensions.WhereIf(
                _plaqueToContractorRepository.GetAll()
                .Include(x => x.Contractor)
                .ThenInclude(x => x.CityInfo)
                .ThenInclude(x => x.StateInfo)
                .Include(x => x.PlaqueToState)
                .ThenInclude(x => x.PlaqueStore)
                .ThenInclude(x => x.Species),
                !input.Filter.IsNullOrWhiteSpace(), u =>
                (u.FromCode <= tempSearch &&
                 u.ToCode >= tempSearch) ||
                u.Contractor.Name.Contains(input.Filter) ||
                u.Contractor.Family.Contains(input.Filter) ||
                u.Contractor.CityInfo.Name.Contains(input.Filter) ||
                u.Contractor.CityInfo.StateInfo.Name.Contains(input.Filter) ||
                u.PlaqueToState.PlaqueStore.Species.Name.Contains(input.Filter));

            return(query);
        }
예제 #2
0
        public async Task <PagedResultDto <PlaqueToContractorListDto> > GetPlaqueToContractor(GetPlaqueToContractorInput input)
        {
            var query = GetFilteredQuery(input);
            var user  = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            var isAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.Admin);

            var isSysAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.SysAdmin);

            var isStateAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.StateAdmin);

            var isCityAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.CityAdmin);

            var isOfficer = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.Officer);

            if (isAdmin || isSysAdmin)
            {
                query = query;
            }
            else if (isStateAdmin)
            {
                var union = _unionInfoRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);
                query = query.Where(x => x.Contractor.CityInfo.StateInfoId == union.StateInfoId);
            }
            else if (isCityAdmin)
            {
                var contractor = _contractorRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);
                query = query.Where(x => x.ContractorId == contractor.Id);
            }
            else
            {
                query = query.Where(x => false);
            }
            var userCount = await query.CountAsync();

            var plaqueToContractors = await query
                                      .OrderBy(input.Sorting)
                                      .PageBy(input)
                                      .ToListAsync();

            var plaqueToContractorsListDto = ObjectMapper.Map <List <PlaqueToContractorListDto> >(plaqueToContractors);

            return(new PagedResultDto <PlaqueToContractorListDto>(
                       userCount,
                       plaqueToContractorsListDto
                       ));
        }