Esempio n. 1
0
        public async Task <ActionResult <PaginatedResultDTO <CompanyContactDTO> > > GetCompanyContacts([FromRoute] Guid id, [FromQuery] PaginationDTO paginationDTO)
        {
            try
            {
                var contacts = _repository.GetContactsForCompany(id);

                var results = await _mapper.ProjectTo <CompanyContactDTO>(contacts.Paginate(paginationDTO)).ToListAsync();

                var response = new PaginatedResultDTO <CompanyContactDTO>
                {
                    Results        = results,
                    CurrentPage    = paginationDTO.Page,
                    RecordsPerPage = paginationDTO.RecordsPerPage,
                    TotalRecords   = await contacts.CountAsync()
                };

                response.TotalPages = (int)Math.Ceiling((decimal)response.TotalRecords / (decimal)response.RecordsPerPage);

                return(Ok(response));
            }
            catch
            {
                // TODO: Log exception
                return(BadRequest());
            }
        }
        public async Task <ActionResult <PaginatedResultDTO <JobApplicationDTO> > > GetJobApplications([FromRoute] Guid userId, [FromQuery] PaginationDTO paginationDTO)
        {
            try
            {
                var applications = _repository.GetJobApplicationsForUser(userId).OrderByDescending(j => j.ApplicationDate);

                var results = await _mapper.ProjectTo <JobApplicationDTO>(applications.Paginate(paginationDTO)).ToListAsync();

                var response = new PaginatedResultDTO <JobApplicationDTO>
                {
                    Results        = results,
                    CurrentPage    = paginationDTO.Page,
                    RecordsPerPage = paginationDTO.RecordsPerPage,
                    TotalRecords   = await applications.CountAsync(),
                };

                response.TotalPages = (int)Math.Ceiling((decimal)response.TotalRecords / (decimal)response.RecordsPerPage);

                return(Ok(response));
            }
            catch
            {
                // TODO: Log exception
                return(BadRequest());
            }
        }