Esempio n. 1
0
        public IActionResult GetCompanies(CompaniesQueryParameters companiesQueryParameters)
        {
            PagedList <Company> pagedList = _companiesRepository.GetCompanies(companiesQueryParameters);

            var previousPageLink = pagedList.HasPrevious
                ? CreateCompaniesResourceUri(companiesQueryParameters, ResourceUriType.PreviousPage)
                : null;

            var nextPageLink = pagedList.HasNext
                ? CreateCompaniesResourceUri(companiesQueryParameters, ResourceUriType.NextPage)
                : null;

            var paginationMetadata = new
            {
                totalCount       = pagedList.TotalCount,
                pageSize         = pagedList.PageSize,
                currentPage      = pagedList.CurrentPage,
                totalPages       = pagedList.TotalPages,
                previousPageLink = previousPageLink,
                nextPageLink     = nextPageLink
            };

            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

            var response = new
            {
                metadata = paginationMetadata,
                data     = pagedList.ToMappedPagedList <Company, CompanyDto>()
            };

            return(Ok(response));
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(string searchQuery)
        {
            IEnumerable <Company> companies;

            if (searchQuery != null)
            {
                companies = await _companiesRep.FindCompaniesByName(searchQuery);
            }
            else
            {
                companies = await _companiesRep.GetCompanies();
            }
            return(View(companies));
        }
        public async Task <IActionResult> GetCompanies(Header header)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Please specify valid Header object!"));
            }

            var companies = await _repo.GetCompanies(header);

            if (companies == null)
            {
                return(NotFound());
            }

            return(Ok(companies));
        }
Esempio n. 4
0
        public async Task <Response <PageModel <CompanyDTO> > > GetCompanies(PageModel model)
        {
            var page = await _repository.GetCompanies(model);

            var result = new PageModel <CompanyDTO>
            {
                Page     = page.Page,
                PageSize = page.PageSize,
                Total    = page.Total,
                Items    = _mapper.Map <IEnumerable <CompanyModel>, IEnumerable <CompanyDTO> >(page.Items)
            };

            return(new Response <PageModel <CompanyDTO> >
            {
                Data = result
            });
        }
Esempio n. 5
0
        public async Task <Response <PageModel <CompanyDetailAdminDTO> > > GetCompanyPage(PageModel model, CompanyFilterAdminDTO filter)
        {
            var mappedFilter        = _mapper.Map <CompanyFilterModel>(filter);
            var companiesEntityPage = await _companiesRepository.GetCompanies(model, mappedFilter);

            var companyDtoPage = _mapper.Map <PageModel <CompanyDetailAdminDTO> >(companiesEntityPage);

            var usersCompaniesEntityList = (await _companiesUsersRepository.GetUsersByCompanies(
                                                companyDtoPage.Items.Select(x => x.Id))).ToList();

            foreach (var company in companyDtoPage.Items)
            {
                var companyUsers = usersCompaniesEntityList.Where(x => x.CompanyId == company.Id).ToList();
                company.UsersCount = companyUsers.Count(x => x.User.Status != UserStatus.Active);
                company.Admins     = _mapper.Map <IEnumerable <UserWithRoleDTO> >(companyUsers.Where(x => x.Status != MembershipStatus.Member));
            }

            return(new Response <PageModel <CompanyDetailAdminDTO> >
            {
                Data = companyDtoPage
            });
        }
 public List <Company> GetCompaniesList()
 {
     return(_companiesRepository.GetCompanies());
 }