示例#1
0
        public async Task <ActionResult <Pagination <IEnumerable <CommandReturnDto> > > > GetAllCommands([FromQuery] CommandParams commandParams)
        {
            IEnumerable <Command> commandItems = new List <Command>();
            int totalItems = 0;

            // TODO: Specification pattern
            if (commandParams.PlatformId.HasValue)
            {
                commandItems = await _repo.GetCommandsByPlatform(
                    (commandParams.PageSize * (commandParams.PageIndex - 1)),
                    commandParams.PageSize,
                    commandParams.PlatformId.GetValueOrDefault());

                totalItems = await _repo.CountAsyncForPlatform(commandParams.PlatformId.GetValueOrDefault());
            }
            else
            {
                commandItems = await _repo.GetAllCommands(
                    (commandParams.PageSize * (commandParams.PageIndex - 1)),
                    commandParams.PageSize);

                totalItems = await _repo.CountAsync();
            }

            var data = _mapper.Map <IEnumerable <CommandReturnDto> >(commandItems);

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