public async Task <List <(int OrderItemId, List <CatalogAttribute> Attributes)> > GetOrderAttributesAsync(List <OrderItem> orderItems) { //var specOrders = new OrdersSpecification(orderId); //var order = (await _orderRepository.ListAsync(specOrders)).FirstOrDefault(); //var orderItem = order.OrderItems.SingleOrDefault(x => x.Id == orderItemId); if (orderItems.Any(x => x.CustomizeItem != null)) { return(null); } var list = new List <(int OrderItemId, List <CatalogAttribute> Attributes)>(); foreach (var orderItem in orderItems) { var spec = new CatalogAttrFilterSpecification(orderItem.ItemOrdered.CatalogItemId); var product = await _itemRepository.GetBySpecAsync(spec); var listItem = (orderItem.Id, new List <CatalogAttribute>()); foreach (var item in product.Attributes) { if ((orderItem.CatalogAttribute1.HasValue && orderItem.CatalogAttribute1 == item.Id) || (orderItem.CatalogAttribute2.HasValue && orderItem.CatalogAttribute2 == item.Id) || (orderItem.CatalogAttribute3.HasValue && orderItem.CatalogAttribute3 == item.Id)) { listItem.Item2.Add(item); } } list.Add(listItem); } return(list); }
public async Task <List <CatalogAttribute> > GetOrderAttributesAsync(int catalogItemId, int?catalogAttribute1, int?catalogAttribute2, int?catalogAttribute3) { var spec = new CatalogAttrFilterSpecification(catalogItemId); var product = await _itemRepository.GetBySpecAsync(spec); var list = new List <CatalogAttribute>(); if (product != null) { foreach (var item in product.Attributes) { if ((catalogAttribute1.HasValue && catalogAttribute1 == item.Id) || (catalogAttribute2.HasValue && catalogAttribute2 == item.Id) || (catalogAttribute3.HasValue && catalogAttribute3 == item.Id)) { list.Add(item); } } } return(list); }
private async Task <List <BasketItemViewModel> > GetBasketItemsAsync(IReadOnlyCollection <BasketItem> basketItems) { var items = new List <BasketItemViewModel>(); foreach (var i in basketItems) { var itemModel = new BasketItemViewModel() { Id = i.Id, UnitPrice = i.UnitPrice, Quantity = i.Quantity, CatalogItemId = i.CatalogItemId, CustomizeName = i.CustomizeName }; var spec = new CatalogAttrFilterSpecification(i.CatalogItemId); var item = await _itemRepository.GetSingleBySpecAsync(spec); if (item != null) { itemModel.PictureUrl = _uriComposer.ComposePicUri(item.PictureUri); itemModel.ProductName = item.Name; } foreach (var attr in item.CatalogAttributes) { if ((i.CatalogAttribute1.HasValue && i.CatalogAttribute1 == attr.Id) || (i.CatalogAttribute2.HasValue && i.CatalogAttribute2 == attr.Id) || (i.CatalogAttribute3.HasValue && i.CatalogAttribute3 == attr.Id)) { itemModel.Attributes.Add(new AttributeViewModel { Name = attr.Name, Label = EnumHelper <AttributeType> .GetDisplayValue(attr.Type) }); } } items.Add(itemModel); } return(items); }