Esempio n. 1
0
        public async Task <IEnumerable <TenantModel> > Get(TenantFilterModel filterModel)
        {
            List <Tenant> tenantsList;

            if (filterModel?.TenantIds != null && filterModel.TenantIds.Any())
            {
                tenantsList = (await _tenantRepository.GetAsync(x => filterModel.TenantIds.Contains(x.Id))).ToList();
            }
            else
            {
                tenantsList = (await _tenantRepository.GetAsync()).ToList();
            }
            var companyIds = tenantsList.SelectMany(x => x.Companies.Select(c => c.CompanyId)).Distinct().ToList();
            var companies  = (await _companyManager.GetCompanies(new CompanyFilter {
                CompanyIds = companyIds
            })).Data.ToHashSet();
            var result     = new List <TenantModel>();

            foreach (var tenant in tenantsList)
            {
                var model = new TenantModel
                {
                    Id        = tenant.Id,
                    Name      = tenant.TenantName,
                    Phone     = tenant.Phone,
                    Companies = companies.Where(x => tenant.Companies.Select(c => c.CompanyId).Contains(x.Id)).ToList()
                };
                result.Add(model);
            }
            return(result);
        }
Esempio n. 2
0
        public async Task <IEnumerable <TenantWithCompaniesSimpleModel> > GetSimple(TenantFilterModel filterModel)
        {
            List <Tenant> tenantsList = new List <Tenant>();

            if (filterModel?.TenantIds != null && filterModel.TenantIds.Any())
            {
                tenantsList = (await _tenantRepository.GetAsync(x => filterModel.TenantIds.Contains(x.Id))).ToList();
            }
            else
            {
                tenantsList = (await _tenantRepository.GetAsync()).ToList();
            }
            var companyIds        = tenantsList.SelectMany(x => x.Companies.Select(c => c.CompanyId)).Distinct().ToList();
            var companies         = (await _companyRepository.GetAsync());
            var companyBaseModels = (from c in companies
                                     join cid in companyIds on c.Id equals cid
                                     select new CompanyBaseModel
            {
                Id = c.Id,
                CompanyName = c.CompanyName
            }).ToList().ToHashSet();
            var result = tenantsList.Select(x => new TenantWithCompaniesSimpleModel
            {
                Id        = x.Id,
                Name      = x.TenantName,
                Phone     = x.Phone,
                Companies = companyBaseModels.Where(c => x.Companies.Select(tc => tc.CompanyId).Contains(c.Id)).ToList()
            });

            return(result);
        }
        public async Task <IEnumerable <TenantModel> > Get(TenantFilterModel filterModel)
        {
            var serviceProvidersList = (await _serviceProviderRepository.GetAsync(x => filterModel.TenantIds.Contains(x.Id))).ToList();
            var companyIds           = serviceProvidersList.SelectMany(x => x.Companies.Select(c => c.CompanyId)).Distinct().ToList();
            var companies            = (await _companyManager.GetCompanies(new CompanyFilter {
                CompanyIds = companyIds
            })).Data.ToHashSet();
            var result = new List <TenantModel>();

            foreach (var serviceProvider in serviceProvidersList)
            {
                var model = new TenantModel
                {
                    Id        = serviceProvider.Id,
                    Name      = serviceProvider.TenantName,
                    Phone     = serviceProvider.Phone,
                    Companies = companies.Where(x => serviceProvider.Companies.Select(c => c.CompanyId).Contains(x.Id)).ToList()
                };
                result.Add(model);
            }
            return(result);
        }
Esempio n. 4
0
        public async Task <IActionResult> GetSimple([FromQuery] TenantFilterModel filterModel)
        {
            var tenant = await _tenantService.GetSimple(filterModel);

            return(Ok(tenant));
        }