示例#1
0
        public override async Task <List <ShippingMethod> > Query(ListShippingMethodsCommand command)
        {
            var query = DbContext.ShippingMethods;

            return(await query.ToListAsync());
        }
        public override async Task <ActionResult <List <ShippingMethodDto> > > Handle(ListShippingMethodsCommand command)
        {
            var shippingMethods = await _listShippingMethodsQuery.Query(command);

            if (shippingMethods == null)
            {
                return(Error());
            }

            var phrases = await _listPhrasesByNameQuery.Query(new ListPhrasesByNameCommand(shippingMethods.Select(o => o.Code)));

            var shippingMethodsDto = new List <ShippingMethodDto>();

            foreach (var shippingMethod in shippingMethods)
            {
                shippingMethodsDto.Add(new ShippingMethodDto()
                {
                    Price = shippingMethod.Price,
                    Text  = (phrases.FirstOrDefault(o => o.Code == shippingMethod.Code)?.Value ?? shippingMethod.Code) + $" + {shippingMethod.Price.ToCurrencyString()}€",
                    Value = shippingMethod.Code
                });
            }

            return(Ok(shippingMethodsDto));
        }