private void AddItemIfMatch(OrderItem orderItem, Domain.AOReOrderItem reOrderItem, Product product, string attributeInfo, ProductAttributeCombination comb) { string attributeInfoComb = GetAttributeInfo(comb.AttributesXml); if (attributeInfoComb == attributeInfo) { int manufacturerId = 0; var manufacturer = _manufacturerService.GetProductManufacturersByProductId(product.Id).FirstOrDefault(); if (manufacturer != null) { manufacturerId = manufacturer.ManufacturerId; } if (string.IsNullOrEmpty(comb.Gtin) == false) { reOrderItem = _context.AOReOrderItems.Where(o => o.EAN == comb.Gtin).FirstOrDefault(); } else { reOrderItem = _context.AOReOrderItems.Where(o => o.ManufacturerProductId == product.ManufacturerPartNumber && o.ManufacturerId == manufacturerId).FirstOrDefault(); } AddOrUpdateItem(orderItem, reOrderItem, product, attributeInfo, comb, manufacturerId); } else { _logger.Warning("attributeInfoComb != attributeInfo: " + attributeInfoComb + " != " + attributeInfo); } }
private void AddReOrderItem(OrderItem orderItem, Domain.AOReOrderItem reOrderItem, List <ProductAttributeCombination> combinations, Product product) { string attributeInfo = GetAttributeInfo(orderItem.AttributesXml); foreach (ProductAttributeCombination comb in combinations) { AddItemIfMatch(orderItem, reOrderItem, product, attributeInfo, comb); } }
private void AddOrUpdateItem(OrderItem orderItem, Domain.AOReOrderItem reOrderItem, Product product, string attributeInfo, ProductAttributeCombination comb, int manufacturerId) { if (reOrderItem == null) { AddItem(orderItem, product, attributeInfo, comb, manufacturerId); } else { UpdateItem(orderItem, reOrderItem); } _handledOrderItems++; }
private void AddItem(OrderItem orderItem, Product product, string attributeInfo, ProductAttributeCombination comb, int manufacturerId) { Domain.AOReOrderItem reOrderItem = new Domain.AOReOrderItem() { EAN = comb.Gtin ?? "", ManufacturerId = manufacturerId, ManufacturerProductId = product.ManufacturerPartNumber, OrderItemId = orderItem.Id, ProductId = comb.ProductId, ProductName = product.Name + attributeInfo, Quantity = orderItem.Quantity, VendorId = product.VendorId }; _context.AOReOrderItems.Add(reOrderItem); _context.SaveChanges(); }
private void UpdateItem(OrderItem orderItem, Domain.AOReOrderItem reOrderItem) { reOrderItem.Quantity += orderItem.Quantity; _context.AOReOrderItems.Update(reOrderItem); _context.SaveChanges(); }