Exemple #1
0
        public async Task <PrintingEditionModel> GetPrintingEditionsAsync(FilterPrintingEditionModel filter, bool isAdmin)
        {
            var responseModel = new PrintingEditionModel();

            var repositoryFilter = _mapperHelper.Map <FilterPrintingEditionModel, DataFilter.FilterPrintingEditionModel>(filter);

            if (repositoryFilter == null)
            {
                responseModel.Errors.Add(Constants.Errors.OccuredProcessing);
                return(responseModel);
            }

            if (!isAdmin)
            {
                repositoryFilter.PriceMinValue = _currencyConverterHelper.Convert(repositoryFilter.Currency, Enums.Currency.USD, repositoryFilter.PriceMinValue);
                repositoryFilter.PriceMaxValue = _currencyConverterHelper.Convert(repositoryFilter.Currency, Enums.Currency.USD, repositoryFilter.PriceMaxValue);
            }

            var printingEditionsModel = await _printingEditionRepository.GetPrintingEditionFilteredDataAsync(repositoryFilter, isAdmin);

            foreach (var printingEdition in printingEditionsModel.Collection)
            {
                var modelItem = printingEdition.MapToModel(filter.Currency);

                if (!isAdmin)
                {
                    modelItem.Price = _currencyConverterHelper.Convert(Enums.Currency.USD, filter.Currency, modelItem.Price);
                }

                responseModel.Items.Add(modelItem);
            }

            responseModel.ItemsCount = printingEditionsModel.CollectionCount;

            return(responseModel);
        }