Beispiel #1
0
        public async Task <PageModel <AutoPartModel> > Handle(GetAutoPartsRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException($"{nameof(request)} of type {nameof(GetAutoPartsRequest)} argument cannot be null.");
            }

            if (!autoPartsSortingTypeMap.ContainsKey(request.SortBy))
            {
                throw new ArgumentException($"No key found with value {request.SortBy} in the {nameof(autoPartsSortingTypeMap)} dictionary. Cannot map the sorting expression.");
            }

            var filter  = mapper.Map <AutoPartsFilter>(request);
            var sorting = autoPartsSortingTypeMap[request.SortBy];

            var result = await autoPartRepository.GetAutoParts(filter, sorting.Key, sorting.Value)
                         .ConfigureAwait(false);

            var items = mapper.Map <AutoPartModel[]>(result.Items);

            foreach (var item in items)
            {
                if (!string.IsNullOrEmpty(item.ImageUrl))
                {
                    item.ImageUrl = await mediator.Send(new GetFileUrlRequest { FileName = item.ImageUrl });
                }
            }

            return(new PageModel <AutoPartModel>
            {
                TotalNumberOfItems = result.TotalNumberOfItems,
                Items = items
            });
        }
Beispiel #2
0
        public async Task <GetAutoPartsResponse> GetAutoParts(int pageSize, AutoPartsFilter filter)
        {
            var request = new GetAutoPartsRequest
            {
                SearchText        = filter.SearchText ?? string.Empty,
                AvailableOnly     = filter.AvailableOnly,
                CarModificationId = filter.CarModificationId,
                CountryId         = filter.CountryId,
                ManufacturerId    = filter.ManufacturerId,
                PageNumber        = filter.PageNumber,
                PageSize          = pageSize,
                SortBy            = filter.Sorting,
                SubCatalogId      = filter.SubCatalogId,
                SupplierId        = filter.SupplierId
            };

            return(await autoPartServiceClient.GetAutoPartsAsync(request));
        }