public async Task <ActionResult> GetFiscalYears() { try { return(Ok(await fiscalyearRepository.GetFiscalYears())); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public async Task <ActionResult <FiscalYearListDTO> > GetFiscalYears([FromQuery] int page = 1, [FromQuery] int itemsPerPage = 20) { try { if (page < 1 || itemsPerPage < 1) { return(BadRequest("Request contained one or more invalid paging values.")); } var fiscalYears = await _fiscalYearRepo.GetFiscalYears() .Skip((page - 1) * itemsPerPage) .Take(itemsPerPage) .OrderBy(f => f.YearDescription) .ToListAsync(); var fiscalYearCount = await _fiscalYearRepo.GetFiscalYears().CountAsync(); var fiscalYearList = _mapper.Map <List <FiscalYear>, List <FiscalYearDTO> >(fiscalYears); var dto = new FiscalYearListDTO { FiscalYears = fiscalYearList, TotalItems = fiscalYearCount, TotalPages = decimal.ToInt32(Math.Ceiling((decimal)fiscalYearCount / (decimal)itemsPerPage)), CurrentPage = page, ItemsPerPage = itemsPerPage }; return(dto); } catch (Exception e) { _logger.LogError("Exception occurred while attempting to retrieve Fiscal Years.\nError: " + e.Message); return(BadRequest()); } }