Beispiel #1
0
        public async Task <ActionResult <SpendResourceDto> > GetSpend(int id)
        {
            var spec  = new SpendWithCategorySpecification(id);
            var spend = await _spendRepo.GetEntityWithSpec(spec);

            if (spend == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(_mapper.Map <Spend, SpendResourceDto>(spend));
        }
Beispiel #2
0
        public async Task <ActionResult <Pagination <SpendResourceDto> > > GetSpends([FromQuery] SpendSpecParams spendParams)
        {
            var spec      = new SpendWithCategorySpecification(spendParams);
            var countSpec = new SpendsWithFiltersForCountSpecification(spendParams);

            var totalItems = await _spendRepo.CountAsync(countSpec);

            var spends = await _spendRepo.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <SpendResourceDto> >(spends);

            return(Ok(new Pagination <SpendResourceDto>(spendParams.PageIndex,
                                                        spendParams.PageSize, totalItems, data)));
        }