Exemple #1
0
        public async Task <PagedResponse <PrintingEditionModel> > GetFilteredPrintingEditionsAsync(PrintingEditionFilterModel model, PaginationFilterModel pagination)
        {
            if (string.IsNullOrWhiteSpace(model.SortBy) && string.IsNullOrWhiteSpace(model.TypeSort))
            {
                model.SortBy   = Constants.Sort.DefaultSortById;
                model.TypeSort = Constants.Sort.DefaultSortByAsc;
            }

            (IEnumerable <PrintingEdition> printingEditions, int count)printingEditions = await _printingEditionRepository.GetFilteredPrintingEditionsAsync(model, pagination);

            var printingEditionModel = _autoMapper.Map <IEnumerable <PrintingEditionModel> >(printingEditions.printingEditions);

            if (model.Currency is not null)
            {
                printingEditionModel.ToList().ForEach(item =>
                {
                    item.Price    = _convertCurrency.Convert(item.Price.Value, item.Currency.Value, model.Currency);
                    item.Currency = (CurrencyType)model.Currency;
                });
            }

            var pagedResponse = new PagedResponse <PrintingEditionModel>
            {
                Data       = printingEditionModel,
                PageNumber = pagination.PageNumber,
                PageSize   = pagination.PageSize,
                TotalItems = printingEditions.count
            };

            return(pagedResponse);
        }