コード例 #1
0
        public List <ProductDto> GetProductsWithFilter(List <int> productListIDs)
        {
            List <ProductDto> ProductList = new List <ProductDto>();

            var          repo1     = Scope.Repository <AssortmentContentView>();
            var          repo2     = Scope.Repository <ProductDescription>();
            var          connector = Repository <Connector>().GetSingle(c => c.ConnectorID == Client.User.ConnectorID);
            ContentLogic logic     = new ContentLogic(Scope, Client.User.ConnectorID.Value);

            foreach (var item in productListIDs)
            {
                ProductDto dto      = new ProductDto();
                var        product1 = repo1.GetSingle(a => a.ProductID == item);
                var        product2 = repo2.GetSingle(b => b.ProductID == item);

                dto.ProductID   = product1.ProductID;
                dto.Name        = product2 == null ? "n/a" : product2.ProductName;
                dto.Description = product1.ShortDescription;
                dto.Price       = logic.CalculatePrice(item, 1, connector, Enumerations.PriceRuleType.UnitPrice);
                dto.Stock       = product1.QuantityOnHand;
                dto.Expected    = product1.QuantityToReceive.ToString();

                ProductList.Add(dto);
            }
            return(ProductList);
        }
コード例 #2
0
 public MailChimpManager()
 {
     Lists         = new ListLogic(ApiKey);
     Members       = new MemberLogic(ApiKey);
     Campaigns     = new CampaignLogic(ApiKey);
     Api           = new ApiLogic(ApiKey);
     Conversations = new ConversationLogic(ApiKey);
     Content       = new ContentLogic(ApiKey);
     Apps          = new AuthorizedAppLogic(ApiKey);
 }
コード例 #3
0
        public PriceResult CalculatePrice(int productID, string formula, int?connectorID)
        {
            connectorID.ThrowIf(c => !c.HasValue, "Connector must be supplied");

            ContentLogic logic = new ContentLogic(Scope, connectorID.Value);

            var price = logic.RoundPrice(productID, formula, connectorID.Value);

            return(new Models.Prices.PriceResult()
            {
                CalculatePrice = price.Key, CostPrice = price.Value
            });
        }
コード例 #4
0
 public MailChimpManager(string apiKey) : base(apiKey)
 {
     Api                   = new ApiLogic(ApiKey);
     Apps                  = new AuthorizedAppLogic(ApiKey);
     AutomationEmails      = new AutomationEmailLogic(ApiKey);
     AutomationEmailQueues = new AutomationEmailQueueLogic(ApiKey);
     Automations           = new AutomationLogic(ApiKey);
     AutomationSubscribers = new AutomationSubscriberLogic(ApiKey);
     Campaigns             = new CampaignLogic(ApiKey);
     Content               = new ContentLogic(ApiKey);
     Conversations         = new ConversationLogic(ApiKey);
     Feedback              = new FeedBackLogic(ApiKey);
     Lists                 = new ListLogic(ApiKey);
     Members               = new MemberLogic(ApiKey);
     Messages              = new MessageLogic(ApiKey);
     Reports               = new ReportLogic(ApiKey);
     TemplateFolders       = new TemplateFolderLogic(ApiKey);
     Templates             = new TemplateLogic(ApiKey);
 }
コード例 #5
0
 public Result DeleteAsync(ContentLogic content, UserLogic user)
 {
     try
     {
         if (user.UploadedCourses.Any(c => c.Audios.Any(a => a.Content == content.Id)) || user.IsAdmin)
         {
             var contentDb = mapper.Map <ContentLogic, ContentDb>(content);
             dbmanager.RemoveAsync(contentDb);
             return(Result.Ok());
         }
         else
         {
             return(Result.Fail("Unauthorized"));
         }
     }
     catch (Exception)
     {
         return(Result.Fail("Exception"));
     }
 }
コード例 #6
0
        public List <ProductPriceResult> GetCalculatedPrice(int productID)
        {
            var products = (from p in Repository <Content>().GetAll()
                            let vendorass = p.Product.VendorAssortments.FirstOrDefault(x => x.VendorID == p.ContentProduct.VendorID)//.VendorPrice.FirstOrDefault().Price)
                                            let vendorprice = vendorass != null ? vendorass.VendorPrices.FirstOrDefault() : null
                                                              let price = vendorprice != null ? vendorprice.Price : 0m
                                                                          where p.ProductID == productID
                                                                          select new ProductPriceResult
            {
                CustomItemNumber = vendorass.CustomItemNumber,
                CostPrice = vendorprice.Price,
                CalculatedPrice = 0.0m, //priceRule.Value,
                Marge = 0,              //- priceRule.Value
                ProductStatus = vendorprice.AssortmentStatus.ConnectorProductStatus.FirstOrDefault(y => y.ConnectorID == p.ConnectorID) != null ?
                                vendorprice.AssortmentStatus.ConnectorProductStatus.FirstOrDefault(y => y.ConnectorID == p.ConnectorID).ConnectorStatus : string.Empty,
                ShortDescription = p.ShortDescription,
                LongDescription = p.LongDescription,
                PriceRuleID = 0,        //priceRule.Key,
                ConnectorDescription = p.Connector.Name,
                ConnectorID = p.ConnectorID
            }).ToList();

            var connectorRepo = Repository <Connector>();

            foreach (var product in products)
            {
                ContentLogic logic = new ContentLogic(Scope, product.ConnectorID);

                var connector = connectorRepo.GetSingle(c => c.ConnectorID == product.ConnectorID);

                var pRule = logic.GetCalculationPriceAndRule(productID, 1, connector, PriceRuleType.UnitPrice);
                product.CalculatedPrice = pRule.Value;
                product.PriceRuleID     = pRule.Key;
                product.Marge           = pRule.Value - product.CostPrice.Value;
            }
            return(products.ToList());
        }
コード例 #7
0
        public MailChimpManager(IOptions <MailchimpOptions> optionsAccessor) : base(optionsAccessor)
        {
            var options = optionsAccessor.Value;

            Activities            = new ActivityLogic(options);
            AbuseReports          = new AbuseReportLogic(options);
            Api                   = new ApiLogic(options);
            Apps                  = new AuthorizedAppLogic(options);
            AutomationEmails      = new AutomationEmailLogic(options);
            AutomationEmailQueues = new AutomationEmailQueueLogic(options);
            Automations           = new AutomationLogic(options);
            AutomationSubscribers = new AutomationSubscriberLogic(options);
            Batches               = new BatchLogic(options);
            Campaigns             = new CampaignLogic(options);
            CampaignFolders       = new CampaignFolderLogic(options);
            Clients               = new ClientLogic(options);
            Content               = new ContentLogic(options);
            Conversations         = new ConversationLogic(options);
            ECommerceStores       = new ECommerceLogic(options);
            Feedback              = new FeedBackLogic(options);
            FileManagerFiles      = new FileManagerFileLogic(options);
            FileManagerFolders    = new FileManagerFolderLogic(options);
            GrowthHistories       = new GrowthHistoryLogic(options);
            InterestCategories    = new InterestCategoryLogic(options);
            Interests             = new InterestLogic(options);
            Lists                 = new ListLogic(options);
            ListSegments          = new ListSegmentLogic(options);
            Members               = new MemberLogic(options);
            MergeFields           = new MergeFieldLogic(options);
            Messages              = new MessageLogic(options);
            Notes                 = new NoteLogic(options);
            Reports               = new ReportLogic(options);
            TemplateFolders       = new TemplateFolderLogic(options);
            Templates             = new TemplateLogic(options);
            WebHooks              = new WebHookLogic(options);
        }
コード例 #8
0
        public async Task <Result> AddAsync(ContentLogic content, UserLogic user)
        {
            try
            {
                var audio = content.Audio;
                if (user.UploadedCourses.Any(c => c.Audios.Contains(audio)) || user.IsAdmin)
                {
                    content.Audio = audio;
                    content.Id    = audio.Content;
                    var contentDb = mapper.Map <ContentLogic, ContentDb>(content);
                    await dbmanager.AddAsync(contentDb);

                    return(Result.Ok());
                }
                else
                {
                    return(Result.Fail("Unauthorized"));
                }
            }
            catch (Exception)
            {
                return(Result.Fail("Exception"));
            }
        }
コード例 #9
0
        public PurchaseRequest GetPurchaseOrder(Concentrator.Objects.Models.Orders.Order order, List <OrderLine> orderLines, Vendor administrativeVendor, Vendor vendor)
        {
            using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
            {
                var customer = order.ShippedToCustomer;

                Dictionary <int, string>           customItemNumbers = new Dictionary <int, string>();
                Dictionary <int, VendorAssortment> VendorAssortments = new Dictionary <int, VendorAssortment>();
                Dictionary <string, string>        additionalItems   = new Dictionary <string, string>();
                ContentLogic logic = new ContentLogic(unit.Scope);
                foreach (var l in orderLines)
                {
                    if (l.Product != null)
                    {
                        //var customItemNumber = l.Product.VendorAssortment.Where(x => x.VendorID == administrativeVendor.VendorID && x.Product == l.Product).Select(x => x.CustomItemNumber).FirstOrDefault();
                        string customItemNumber = logic.GetVendorItemNumber(l.Product, l.CustomerItemNumber, administrativeVendor.VendorID);
                        customItemNumbers.Add(l.ProductID.Value, customItemNumber);

                        var vass = l.Product.VendorAssortments.Where(x => x.VendorID == vendor.VendorID).Select(x => x).FirstOrDefault();
                        VendorAssortments.Add(l.ProductID.Value, vass);
                    }
                    else
                    {
                        var additionalOrderProduct = (from aop in unit.Scope.Repository <AdditionalOrderProduct>().GetAllAsQueryable()
                                                      where aop.ConnectorID == l.Order.ConnectorID &&
                                                      aop.ConnectorProductID == l.CustomerItemNumber &&
                                                      aop.VendorID == administrativeVendor.VendorID
                                                      select aop).FirstOrDefault();

                        if (additionalOrderProduct != null)
                        {
                            additionalItems.Add(l.CustomerItemNumber, additionalOrderProduct.VendorProductID);
                        }
                    }
                }

                var administrativeVendorSettings = administrativeVendor.PreferredConnectorVendors.Where(x => x.ConnectorID == order.ConnectorID).FirstOrDefault();
                var connectorVendorSettings      = vendor.PreferredConnectorVendors.Where(x => x.ConnectorID == order.ConnectorID).FirstOrDefault();

                PurchaseRequest purchaseRequest = new PurchaseRequest()
                {
                    bskIdentifier    = administrativeVendorSettings.VendorIdentifier,
                    Version          = "1.0",
                    PurchaseCustomer = new PurchaseCustomer()
                    {
                        PurchaseCustomerAddress = new PurchaseCustomerAddress()
                        {
                            AddressLine1 = order.ShippedToCustomer.CustomerAddressLine1,
                            AddressLine2 = order.ShippedToCustomer.CustomerAddressLine2,
                            AddressLine3 = order.ShippedToCustomer.CustomerAddressLine3,
                            City         = order.ShippedToCustomer.City,
                            Country      = order.ShippedToCustomer.Country,
                            Name         = order.ShippedToCustomer.CustomerName,
                            ZipCode      = order.ShippedToCustomer.PostCode
                        },
                        PurchaseCustomerContact = new PurchaseCustomerContact()
                        {
                            Email = order.ShippedToCustomer.CustomerEmail,
                            Name  = order.ShippedToCustomer.CustomerName
                        }
                    },
                    PurchaseLines = (from l in orderLines
                                     let customItemNumber = l.Product != null ? customItemNumbers[l.ProductID.Value] : additionalItems[l.CustomerItemNumber]
                                                            let vendorAss = l.Product != null ? VendorAssortments[l.ProductID.Value] : null
                                                                            select new PurchaseLine
                    {
                        ItemNumber = customItemNumber,
                        Price = l.Price.HasValue ? l.Price.Value.ToString() : vendorAss.VendorPrices.FirstOrDefault().Price.Value.ToString(),
                        Product = new Concentrator.Web.Objects.EDI.Purchase.Product()
                        {
                            BrandCode = l.Product.Brand.BrandVendors.Where(x => x.VendorID == administrativeVendorSettings.Vendor.VendorID).Select(x => x.VendorBrandCode).FirstOrDefault(),
                            Description = l.Product.ProductDescriptions.Where(x => x.LanguageID == (int)LanguageTypes.English).Select(x => x.ShortContentDescription).FirstOrDefault() != null ?
                                          l.Product.ProductDescriptions.Where(x => x.LanguageID == (int)LanguageTypes.English).Select(x => x.ShortContentDescription).FirstOrDefault() : l.Product.Contents.Where(x => x.ConnectorID == order.ConnectorID).Select(x => x.ShortDescription).FirstOrDefault(),
                            Description2 = string.Empty,
                            EAN = l.Product.ProductBarcodes.FirstOrDefault() != null ? (l.Product.ProductBarcodes.FirstOrDefault().Barcode.Length == 13 ? l.Product.ProductBarcodes.FirstOrDefault().Barcode : string.Empty) : string.Empty,
                            UPC = l.Product.ProductBarcodes.FirstOrDefault() != null ? (l.Product.ProductBarcodes.FirstOrDefault().Barcode.Length == 12 ? l.Product.ProductBarcodes.FirstOrDefault().Barcode : string.Empty) : string.Empty,
                            ModelNumber = string.Empty,
                            VendorItemNumber = l.Product != null ? l.Product.VendorItemNumber : string.Empty,
                            UnitCost = vendorAss != null ? (vendorAss.VendorPrices.FirstOrDefault().CostPrice.HasValue ? vendorAss.VendorPrices.FirstOrDefault().CostPrice.Value : vendorAss.VendorPrices.FirstOrDefault().Price.Value) : 0,
                            UnitPrice = new Concentrator.Web.Objects.EDI.Purchase.ProductUnitPrice()
                            {
                                HighTaxRate = true,
                                LowTaxRate = false,
                                Text = new string[] { l.Price.HasValue?l.Price.Value.ToString() : vendorAss.VendorPrices.FirstOrDefault().Price.Value.ToString() }
                            }
                        },
                        Quantity = l.GetDispatchQuantity(),
                        Reference = l.OrderLineID,
                        RequestDate = order.ReceivedDate,
                        ShipToNumber = order.ShippedToCustomer.EANIdentifier,
                        SupplierNumber = (connectorVendorSettings != null && !string.IsNullOrEmpty(connectorVendorSettings.VendorIdentifier)) ? connectorVendorSettings.VendorIdentifier : string.Empty,
                        SupplierSalesOrder = l.OrderID,
                        Remark = l.Remarks //,
                                           //SupplierSalesOrder = order.OrderID
                    }).ToArray()
                };
                return(purchaseRequest);
            }
        }
コード例 #10
0
        public override List <WebOrderRequest> GetOrder(Dictionary <Concentrator.Objects.Models.Orders.Order, List <Concentrator.Objects.Models.Orders.OrderLine> > orderLines, Vendor vendor)
        {
            using (IUnitOfWork unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
            {
                var groupedOrders = orderLines;
                var msgID         = groupedOrders.FirstOrDefault().Value.FirstOrDefault().OrderLineID;

                List <WebOrderRequest> orders = new List <WebOrderRequest>();


                foreach (var ord in groupedOrders)
                {
                    var customer = ord.Key.ShippedToCustomer;

                    var soldToCustomer = ord.Key.SoldToCustomer;

                    if (soldToCustomer == null)
                    {
                        soldToCustomer = customer;
                    }

                    string backendCustomerID = "0";

                    if (!string.IsNullOrEmpty(ord.Key.Connector.BackendEanIdentifier))
                    {
                        backendCustomerID = ord.Key.Connector.BackendEanIdentifier;
                    }

                    if (backendCustomerID == "0" && !string.IsNullOrEmpty(ord.Key.ShippedToCustomer.EANIdentifier))
                    {
                        backendCustomerID = ord.Key.ShippedToCustomer.EANIdentifier;
                    }
                    ContentLogic    logic = new ContentLogic(unit.Scope, 0);
                    WebOrderRequest order = new WebOrderRequest()
                    {
                        WebCustomer = new CreateCustomer
                        {
                            CustomerAddress = new WebAddress
                            {
                                AddressLine1 = soldToCustomer.CustomerAddressLine1,
                                AddressLine2 = soldToCustomer.CustomerAddressLine2,
                                AddressLine3 = soldToCustomer.CustomerAddressLine3,
                                Number       = soldToCustomer.HouseNumber,
                                City         = soldToCustomer.City,
                                Country      = soldToCustomer.Country,
                                Name         = soldToCustomer.CustomerName,
                                ZipCode      = soldToCustomer.PostCode
                            },
                            CustomerContact = new WebContact
                            {
                                HomePhoneNumber     = !string.IsNullOrEmpty(soldToCustomer.CustomerTelephone) ? soldToCustomer.CustomerTelephone : string.Empty,
                                Email               = soldToCustomer.CustomerEmail,
                                Name                = soldToCustomer.CustomerName,
                                FaxNumber           = string.Empty,
                                BusinessPhoneNumber = soldToCustomer.CoCNumber,
                                MobilePhoneNumber   = string.Empty,
                                Website             = string.Empty,
                            }
                        },
                        WebOrderDetails = (from c in ord.Value
                                           select new WebOrderRequestDetail
                        {
                            CustomerReference = new CustomerReference
                            {
                                CustomerOrder = (string.IsNullOrEmpty(c.CustomerOrderNr) ? customer.CustomerName : c.CustomerOrderNr).Cap(25),
                                CustomerOrderLine = c.OrderLineID.ToString(),
                            },
                            ProductIdentifier = new ProductIdentifier
                            {
                                //ProductNumber = c.Product != null ? (c.Product.VendorAssortment.Where(x => x.VendorID == vendor.VendorID).FirstOrDefault() != null ? c.Product.VendorAssortment.Where(x => x.VendorID == vendor.VendorID).FirstOrDefault().CustomItemNumber : c.CustomerItemNumber) : c.CustomerItemNumber
                                ProductNumber = logic.GetVendorItemNumber(c.Product, c.CustomerItemNumber, vendor.VendorID)
                            },
                            //VendorItemNumber = c.Product != null ? c.Product.VendorItemNumber : string.Empty,
                            Quantity = c.GetDispatchQuantity(),
                            WareHouseCode = c.WareHouseCode,
                            UnitPrice = c.PriceOverride && c.Price.HasValue ? decimal.Floor((decimal)c.Price.Value * 10000).ToString() : string.Empty
                        }).ToArray(),
                        WebOrderHeader = new WebOrderRequestHeader
                        {
                            EdiVersion             = ord.Key.EdiVersion,
                            BSKIdentifier          = int.Parse(ord.Key.BSKIdentifier),
                            CustomerOrderReference = (string.IsNullOrEmpty(ord.Key.CustomerOrderReference) ? ord.Key.ShippedToCustomer.CustomerName : ord.Key.CustomerOrderReference).Cap(25),
                            ShipToCustomer         = new Concentrator.Web.Objects.EDI.Customer
                            {
                                Contact = new Contact
                                {
                                    Email       = customer.CustomerEmail,
                                    Name        = customer.CustomerName,
                                    PhoneNumber = !string.IsNullOrEmpty(customer.CustomerTelephone) ? customer.CustomerTelephone : string.Empty
                                },
                                EanIdentifier = backendCustomerID                                                                          // customer.EANIdentifier
                            },
                            CustomerOverride = new CustomerOverride
                            {
                                CustomerContact = new Contact
                                {
                                    Email       = customer.CustomerEmail,
                                    Name        = customer.CustomerName,
                                    PhoneNumber = !string.IsNullOrEmpty(customer.CustomerTelephone) ? customer.CustomerTelephone : string.Empty
                                },
                                Dropshipment = ord.Key.isDropShipment.HasValue ? ord.Key.isDropShipment.Value : false,
                                OrderAddress = new Address
                                {
                                    AddressLine1 = customer.CustomerAddressLine1 + " " + customer.HouseNumber,
                                    AddressLine2 = customer.CustomerAddressLine2,
                                    AddressLine3 = customer.CustomerAddressLine3,
                                    City         = customer.City,
                                    Country      = customer.Country,
                                    Name         = customer.CustomerName.Cap(40),
                                    ZipCode      = customer.PostCode
                                }
                            },
                            WebSiteOrderNumber         = ord.Key.WebSiteOrderNumber,
                            PaymentInstrument          = ord.Key.PaymentInstrument,
                            PaymentTermsCode           = ord.Key.PaymentTermsCode,
                            RouteCode                  = ord.Key.RouteCode,
                            HoldCode                   = ord.Key.HoldCode,
                            BackOrdersAllowed          = ord.Key.BackOrdersAllowed.Value,
                            BackOrdersAllowedSpecified = ord.Key.BackOrdersAllowed.Value
                        },
                        Version = "1.0"
                    };

                    orders.Add(order);
                }
                return(orders);
            }
        }
コード例 #11
0
        public override DirectShipmentRequest GetDirectShipmentOrder(Concentrator.Objects.Models.Orders.Order order, List <Concentrator.Objects.Models.Orders.OrderLine> orderLines, Vendor administrativeVendor, Vendor vendor)
        {
            var customer = order.ShippedToCustomer;

            using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
            {
                Dictionary <int, string>           customItemNumbers = new Dictionary <int, string>();
                Dictionary <int, VendorAssortment> VendorAssortments = new Dictionary <int, VendorAssortment>();
                Dictionary <string, string>        additionalItems   = new Dictionary <string, string>();
                ContentLogic logic = new ContentLogic(unit.Scope);
                foreach (var l in orderLines)
                {
                    if (l.Product != null)
                    {
                        string customItemNumber1 = logic.GetVendorItemNumber(l.Product, l.CustomerItemNumber, administrativeVendor.VendorID);
                        var    customItemNumber  = l.Product.VendorAssortments.Where(x => x.VendorID == administrativeVendor.VendorID && x.Product == l.Product).Select(x => x.CustomItemNumber).FirstOrDefault();
                        //l.ProductID.HasValue ? ContentLogic.GetVendorProductID(l.ProductID.Value, administrativeVendor.VendorID, l.CustomerItemNumber) : l.CustomerItemNumber;

                        customItemNumbers.Add(l.ProductID.Value, customItemNumber);

                        var vass = l.Product.VendorAssortments.Where(x => x.VendorID == vendor.VendorID).Select(x => x).FirstOrDefault();
                        VendorAssortments.Add(l.ProductID.Value, vass);
                    }
                    else
                    {
                        var additionalOrderProduct = (from aop in unit.Scope.Repository <AdditionalOrderProduct>().GetAllAsQueryable()
                                                      where aop.ConnectorID == l.Order.ConnectorID &&
                                                      aop.ConnectorProductID == l.CustomerItemNumber &&
                                                      aop.VendorID == administrativeVendor.VendorID
                                                      select aop).FirstOrDefault();

                        if (additionalOrderProduct != null && !additionalItems.ContainsKey(l.CustomerItemNumber))
                        {
                            additionalItems.Add(l.CustomerItemNumber, additionalOrderProduct.VendorProductID);
                        }
                    }
                }

                var administrativeVendorSettings = administrativeVendor.PreferredConnectorVendors.Where(x => x.ConnectorID == order.ConnectorID).FirstOrDefault();
                var connectorVendorSettings      = vendor.PreferredConnectorVendors.Where(x => x.ConnectorID == order.ConnectorID).FirstOrDefault();

                DirectShipmentRequest directShipmentOrder = new DirectShipmentRequest()
                {
                    bskIdentifier          = !string.IsNullOrEmpty(administrativeVendorSettings.VendorIdentifier) ? administrativeVendorSettings.VendorIdentifier : order.BSKIdentifier.ToString(),
                    Version                = "1.0",
                    DirectShipmentCustomer = new DirectShipmentCustomer()
                    {
                        DirectShipmentCustomerAddress = new DirectShipmentCustomerAddress()
                        {
                            AddressLine1 = order.ShippedToCustomer.CustomerAddressLine1,
                            AddressLine2 = order.ShippedToCustomer.CustomerAddressLine2,
                            AddressLine3 = order.ShippedToCustomer.CustomerAddressLine3,
                            City         = order.ShippedToCustomer.City,
                            Country      = order.ShippedToCustomer.Country,
                            Name         = order.ShippedToCustomer.CustomerName,
                            ZipCode      = order.ShippedToCustomer.PostCode,
                            Number       = order.ShippedToCustomer.HouseNumber
                        },
                        DirectShipmentCustomerContact = new DirectShipmentCustomerContact()
                        {
                            Email = order.ShippedToCustomer.CustomerEmail,
                            Name  = order.ShippedToCustomer.CustomerName
                        }
                    },
                    DirectShipmentLines = (from l in orderLines
                                           let customItemNumber = l.Product != null ? customItemNumbers[l.ProductID.Value] : additionalItems[l.CustomerItemNumber]
                                                                  let vendorAss = l.Product != null ? VendorAssortments[l.ProductID.Value] : null
                                                                                  let description = l.Product != null ? (l.Product.ProductDescriptions.Where(x => x.LanguageID == (int)LanguageTypes.English).Select(x => x.ShortContentDescription).FirstOrDefault() != null ?
                                                                                                                         l.Product.ProductDescriptions.Where(x => x.LanguageID == (int)LanguageTypes.English).Select(x => x.ShortContentDescription).FirstOrDefault() : l.Product.Contents.Where(x => x.ConnectorID == order.ConnectorID).Select(x => x.ShortDescription).FirstOrDefault()) : "Additional Item"
                                                                                                    let unitCost = (l.ProductID.HasValue ? logic.CalculatePrice(l.ProductID.Value, l.GetDispatchQuantity(), l.Order.Connector, PriceRuleType.CostPrice) : (decimal)l.Price.Value)
                                                                                                                   let unitPrice = (l.ProductID.HasValue ? logic.CalculatePrice(l.ProductID.Value, l.GetDispatchQuantity(), l.Order.Connector, PriceRuleType.UnitPrice) : (decimal)l.Price.Value)
                                                                                                                                   select new DirectShipmentLine
                    {
                        ItemNumber = customItemNumber,
                        Price = l.Price.HasValue ? l.Price.Value.ToString() : vendorAss.VendorPrices.FirstOrDefault().Price.Value.ToString(),
                        Product = (l.ProductID.HasValue ? new Concentrator.Web.Objects.EDI.DirectShipment.Product()
                        {
                            BrandCode = l.Product.Brand.BrandVendors.Where(x => x.VendorID == administrativeVendorSettings.Vendor.VendorID).Select(x => x.VendorBrandCode).FirstOrDefault(),
                            Description = string.IsNullOrEmpty(description) ? vendorAss.ShortDescription : description,
                            Description2 = string.Empty,
                            EAN = l.Product.ProductBarcodes.FirstOrDefault() != null ? (l.Product.ProductBarcodes.FirstOrDefault().Barcode.Length == 13 ? l.Product.ProductBarcodes.FirstOrDefault().Barcode : string.Empty) : string.Empty,
                            UPC = l.Product.ProductBarcodes.FirstOrDefault() != null ? (l.Product.ProductBarcodes.FirstOrDefault().Barcode.Length == 12 ? l.Product.ProductBarcodes.FirstOrDefault().Barcode : string.Empty) : string.Empty,
                            ModelNumber = string.Empty,
                            VendorItemNumber = l.Product != null ? l.Product.VendorItemNumber : string.Empty,
                            UnitCost = unitCost > 0 ? unitCost : (vendorAss != null ?
                                                                  (vendorAss.VendorPrices.FirstOrDefault().CostPrice.HasValue ? vendorAss.VendorPrices.FirstOrDefault().CostPrice.Value : (vendorAss.VendorPrices.FirstOrDefault().Price.HasValue ? vendorAss.VendorPrices.FirstOrDefault().Price.Value : 0))
                                                  : 0),
                            UnitPrice = new Concentrator.Web.Objects.EDI.DirectShipment.ProductUnitPrice()
                            {
                                HighTaxRate = true,
                                LowTaxRate = false,
                                Text = new string[] { unitPrice > 0 ? unitPrice.ToString() : (l.Price.HasValue ? l.Price.Value.ToString() : (vendorAss.VendorPrices.FirstOrDefault().Price.HasValue ? vendorAss.VendorPrices.FirstOrDefault().Price.Value.ToString() : "0")) }
                            }
                        } : new Concentrator.Web.Objects.EDI.DirectShipment.Product()
                        {
                        }),
                        Quantity = l.GetDispatchQuantity(),
                        Reference = !string.IsNullOrEmpty(order.ShippedToCustomer.CustomerName) ? order.ShippedToCustomer.CustomerName : string.Empty,
                        RequestDate = order.ReceivedDate,
                        ShipToNumber = order.ShippedToCustomer.EANIdentifier,
                        SupplierNumber = (connectorVendorSettings != null && !string.IsNullOrEmpty(connectorVendorSettings.VendorIdentifier)) ? connectorVendorSettings.VendorIdentifier : string.Empty,
                        SupplierSalesOrder = l.OrderID,
                        WebsiteNumber = order.WebSiteOrderNumber,
                        Remark = l.Remarks //,
                                           //SupplierSalesOrder = order.OrderID
                    }).ToArray()
                };
                return(directShipmentOrder);
            }
        }
コード例 #12
0
ファイル: Service.cs プロジェクト: RoyMolenaar77/Spider_test
        public List <AssortmentStockPriceProduct> GetStockAndPrices()
        {
            var cStatuses = _db.Query <ConnectorProductStatus>("SELECT * FROM ConnectorProductStatus WHERE ConnectorID = @0", connectorID).ToList();
            ProductStatusConnectorMapper mapper = new ProductStatusConnectorMapper(connectorID, cStatuses);
            ContentLogic logic = new ContentLogic(_db, connectorID);

            logic.FillRetailStock(_db);

            var relatedProductTypeList = _db.Query <RelatedProductType>("SELECT * FROM RelatedProductType").ToDictionary(x => x.RelatedProductTypeID, y => y);

            var calculatedPrices = _db.Query <Concentrator.Objects.Models.Prices.CalculatedPriceView>(
                @"EXECUTE GetCalculatedPriceView @0", connectorID);

            logic.FillPriceInformation(calculatedPrices);

            var recordsSource = _db.Query <AssortmentContentView>("EXECUTE GetAssortmentContentView @0", connectorID).Where(x => x.BrandID > 0);

            if (_productID.HasValue)
            {
                int id = _productID.Value;

                if (id > 0)
                {
                    recordsSource = recordsSource.Where(x => x.ProductID == id);
                }
            }

            var records      = recordsSource.ToList();
            int totalRecords = records.Count;

            var vendorstocktypes    = _db.Query <VendorStockType>("SELECT * FROM VendorStockTypes").ToList();
            var relatedProductsList = GetRelatedProducts();

            SynchronizedCollection <AssortmentStockPriceProduct> assortmentList = new SynchronizedCollection <AssortmentStockPriceProduct>();
            ParallelOptions options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 8
            };

            Parallel.ForEach(Partitioner.Create(0, totalRecords), options, (range, loopState) =>
            {
                List <AssortmentStockPriceProduct> list = new List <AssortmentStockPriceProduct>();
                for (int idx = range.Item1; idx < range.Item2; idx++)
                {
                    var a               = records[idx];
                    var stockRetail     = logic.RetailStock(a.ProductID, _connector);
                    var prices          = logic.CalculatePrice(a.ProductID);
                    var relatedProducts = relatedProductsList.ContainsKey(a.ProductID) ? relatedProductsList[a.ProductID] : new List <RelatedProduct>();


                    list.Add(new AssortmentStockPriceProduct
                    {
                        RelatedProducts = (from rp in relatedProducts.Distinct()
                                           where rp.IsConfigured
                                           select new AssortmentRelatedProduct()
                        {
                            IsConfigured = rp.IsConfigured,
                            RelatedProductID = rp.RelatedProductID,
                            TypeID = rp.RelatedProductTypeID,
                            Type = relatedProductTypeList[rp.RelatedProductTypeID].Type,
                            Index = rp.Index,
                            MapsToMagentoTypeID = relatedProductTypeList[rp.RelatedProductTypeID].TypeMapsToMagentoTypeID
                        }).ToList(),
                        Visible             = a.Visible,
                        ProductID           = a.ProductID,
                        ManufacturerID      = a.VendorItemNumber.Trim(),
                        IsNonAssortmentItem = a.IsNonAssortmentItem ?? false,
                        IsConfigurable      = a.IsConfigurable,
                        CustomProductID     = a.CustomItemNumber,

                        Stock = new AssortmentStock()
                        {
                            QuantityToReceive    = a.QuantityToReceive ?? 0,
                            InStock              = a.QuantityOnHand,
                            StockStatus          = a.ConnectorStatus,
                            PromisedDeliveryDate = a.PromisedDeliveryDate
                        },

                        RetailStock = (from rs in stockRetail
                                       select new AssortmentRetailStock()
                        {
                            CostPrice = rs.UnitCost ?? 0,
                            VendorCode = rs.BackendVendorCode,
                            InStock = rs.QuantityOnHand,
                            StockStatus = mapper.GetForConnector(rs.ConcentratorStatusID),
                            Name = rs.VendorStockTypeID == 1 ? rs.vendorName : vendorstocktypes.Where(x => x.VendorStockTypeID == rs.VendorStockTypeID).Select(x => x.StockType).FirstOrDefault(),
                            PromisedDeliveryDate = rs.PromisedDeliveryDate,
                            QuantityToReceive = rs.QuantityToReceive ?? 0
                        }).ToList(),

                        Prices = (from p in prices
                                  select new AssortmentPrice()
                        {
                            CommercialStatus = p.CommercialStatus,
                            CostPrice = p.CostPrice ?? 0,
                            SpecialPrice = p.SpecialPrice,
                            MinimumQuantity = p.MinimumQuantity ?? 0,
                            TaxRate = p.TaxRate ?? 21,
                            UnitPrice = p.Price
                        }).ToList()
                    });
                }

                foreach (var item in list)
                {
                    assortmentList.Add(item);
                }
            }); return(assortmentList.Distinct().ToList());
        }
コード例 #13
0
ファイル: Service.cs プロジェクト: RoyMolenaar77/Spider_test
        public List <AssortmentProductInfo> GetAssortment(bool importFullContent, bool shopInformation, string customerID, bool showProductGroups, int languageID, bool showRelatedProducts = true)
        {
            var inactiveGroups = GetInactiveGroupsAndTheirChilds(connectorID);

            string mappingsToExcludeStatement = string.IsNullOrEmpty(inactiveGroups) ? "" : string.Format(" and MasterGroupMappingID not in ({0})", inactiveGroups);

            var productGroupsQuery = string.Format("SELECT * FROM ContentProductGroup WHERE ConnectorID = {0} and IsExported = 1 AND MasterGroupMappingID is NOT NULL {1}", connectorID, mappingsToExcludeStatement);

            var productGroups = _db.Query <ContentProductGroup>(productGroupsQuery).GroupBy(c => c.ProductID).ToDictionary(c => c.Key, c => c.ToList());
            var cStatuses     = _db.Query <ConnectorProductStatus>("SELECT * FROM ConnectorProductStatus WHERE ConnectorID = @0", connectorID).ToList();

            ProductStatusConnectorMapper mapper = new ProductStatusConnectorMapper(connectorID, cStatuses);
            ContentLogic logic = new ContentLogic(_db, connectorID);

            logic.FillRetailStock(_db);

            var calculatedPrices = _db.Query <Concentrator.Objects.Models.Prices.CalculatedPriceView>(
                @"EXECUTE GetCalculatedPriceView @0", connectorID);

            logic.FillPriceInformation(calculatedPrices);


            var connectorSystem = _db.Single <ConnectorSystem>("SELECT * FROM ConnectorSystem WHERE ConnectorSystemID = @0", _connector.ConnectorSystemID.Value);

            bool magento         = _connector.ConnectorSystemID.HasValue && connectorSystem.Name == "Magento";
            var  defaultLanguage = _db.FirstOrDefault <ConnectorLanguage>("SELECT * FROM ConnectorLanguage WHERE ConnectorID = @0", connectorID);

            defaultLanguage.ThrowIfNull("No default Language specified for connector");

            if (languageID == 0)
            {
                //languageID = EntityExtensions.GetValueByKey(con.ConnectorSettings, "LanguageID", 2);
                var language = _db.FirstOrDefault <ConnectorLanguage>("SELECT * FROM ConnectorLanguage WHERE ConnectorID = @0", connectorID);
                language.ThrowIfNull("No Language specified for connector");

                languageID = language.LanguageID;
            }

            var recordsSource = _db.Query <AssortmentContentView>("EXECUTE GetAssortmentContentView @0", connectorID).Where(x => x.BrandID > 0);

            if (_productID.HasValue)
            {
                int id = _productID.Value;

                if (id > 0)
                {
                    recordsSource = recordsSource.Where(x => x.ProductID == id);
                }
            }

            var records = recordsSource.ToList();

            var barcodes = _db.Query <ProductBarcodeView>("SELECT * FROM ProductBarcodeView WHERE ConnectorID = @0 and BarcodeType = @1", connectorID, (int)BarcodeTypes.Default).ToList();


            var brands = _db.Query <Brand>("SELECT * FROM Brand").ToList();


            List <ImageView> productImages = new List <ImageView>();

            if (importFullContent)
            {
                productImages = _db.Query <ImageView>("SELECT * FROM ImageView WHERE ConnectorID = @0 AND ImageType = @1", connectorID, "Product").ToList();
            }

            int totalRecords = records.Count;


            List <CrossLedgerclass> crossLedgerClasses = null;

            if (shopInformation)
            {
                crossLedgerClasses = _db.Query <CrossLedgerclass>("SELECT * FROM CrossLedgerClass WHERE ConnectorID = @0", connectorID).ToList();
            }

            var vendorstocktypes = _db.Query <VendorStockType>("SELECT * FROM VendorStockTypes").ToList();

            List <MasterGroupMapping> mappingslist = null;
            Dictionary <int, List <MasterGroupMappingMedia> > mappingMediaList = new Dictionary <int, List <MasterGroupMappingMedia> >();
            List <MasterGroupMapping> parentMappingList = new List <MasterGroupMapping>();

            if (showProductGroups)
            {
                string mappingListQuery = string.Format("SELECT * FROM MasterGroupMapping WHERE ConnectorID = {0} {1}", connectorID, mappingsToExcludeStatement);
                mappingslist = _db.Query <MasterGroupMapping>(mappingListQuery).ToList();

                string mappingMediaQuery = @"SELECT MGMM.* 
                                     FROM MasterGroupMapping MGM 
                                     LEFT JOIN MasterGroupMappingMedia MGMM ON MGM.MasterGroupMappingID = MGMM.MasterGroupMappingID 
                                     WHERE MasterGroupMappingMediaID IS NOT NULL AND MGM.ConnectorID = {0} {1}";

                foreach (var masterGroupMappingMedia in _db.Query <MasterGroupMappingMedia>(string.Format(mappingMediaQuery, connectorID, mappingsToExcludeStatement)))
                {
                    if (!mappingMediaList.ContainsKey(masterGroupMappingMedia.MasterGroupMappingID))
                    {
                        mappingMediaList.Add(masterGroupMappingMedia.MasterGroupMappingID, new List <MasterGroupMappingMedia>());
                    }

                    mappingMediaList[masterGroupMappingMedia.MasterGroupMappingID].Add(masterGroupMappingMedia);
                }

                if (_connector.ParentConnectorID.HasValue)
                {
                    string parentMappingListQuery = string.Format("SELECT * FROM MasterGroupMapping WHERE ConnectorID = {0} {1}", _connector.ParentConnectorID.Value, mappingsToExcludeStatement);
                    parentMappingList = _db.Query <MasterGroupMapping>(parentMappingListQuery).ToList();

                    foreach (var masterGroupMappingMedia in _db.Query <MasterGroupMappingMedia>(string.Format(mappingMediaQuery, _connector.ParentConnectorID.Value, mappingsToExcludeStatement)))
                    {
                        if (!mappingMediaList.ContainsKey(masterGroupMappingMedia.MasterGroupMappingID))
                        {
                            mappingMediaList.Add(masterGroupMappingMedia.MasterGroupMappingID, new List <MasterGroupMappingMedia>());
                        }

                        mappingMediaList[masterGroupMappingMedia.MasterGroupMappingID].Add(masterGroupMappingMedia);
                    }
                }
            }

            var preferredVendor = _db.FirstOrDefault <PreferredConnectorVendor>("SELECT * FROM PreferredConnectorVendor WHERE ConnectorID = @0 AND IsPreferred = 1", connectorID);
            int?vendorid        = null;

            if (preferredVendor != null)
            {
                vendorid = preferredVendor.VendorID;
            }

            var relatedProductTypeList = _db.Query <RelatedProductType>("SELECT * FROM RelatedProductType").ToDictionary(x => x.RelatedProductTypeID, y => y);

            var styleType = relatedProductTypeList.Where(c => c.Value.Type == "Style").FirstOrDefault();

            var relatedProductsList = GetRelatedProducts();

            var configAttributesListSource = _db.Query <ProductAttributeMetaData>(
                @"SELECT ProductID, PAMD.*
											FROM ProductAttributeConfiguration PAC
											INNER JOIN ProductAttributeMetaData PAMD ON (PAC.AttributeID = PAMD.AttributeID)"
                );

            var configAttributesList = (from f in configAttributesListSource
                                        group f by f.ProductID into grouped
                                        select grouped).ToDictionary(x => x.Key, y => y.ToList());

            var productGroupNames        = _db.Query <MasterGroupMappingLanguage>("SELECT * FROM MasterGroupMappingLanguage WHERE LanguageID = @0", languageID).Select(c => new { c.MasterGroupMappingID, c.Name }).ToDictionary(c => c.MasterGroupMappingID, c => c.Name);
            var productGroupNamesDefault = _db.Query <MasterGroupMappingLanguage>("SELECT * FROM MasterGroupMappingLanguage WHERE LanguageID = @0", defaultLanguage.LanguageID).Select(c => new { c.MasterGroupMappingID, c.Name }).ToDictionary(c => c.MasterGroupMappingID, c => c.Name);
            var productGroupDescriptions = _db.Query <MasterGroupMappingDescription>("SELECT * FROM MasterGroupMappingDescription WHERE LanguageID = @0", languageID).Select(c => new { c.MasterGroupMappingID, c.Description }).ToDictionary(c => c.MasterGroupMappingID, c => c.Description);

            var productGroupCustomLabelsForThisConnector
                = _db.Query <MasterGroupMappingCustomLabel>("SELECT * FROM MasterGroupMappingCustomLabel WHERE LanguageID = @0 AND ConnectorID = @1", languageID, connectorID).Select(c => new { c.MasterGroupMappingID, c.CustomLabel }).ToDictionary(c => c.MasterGroupMappingID, c => c.CustomLabel);

            var productGroupCustomLabelsForDefaultConnector = _db.Query <MasterGroupMappingCustomLabel>(@"SELECT * FROM MasterGroupMappingCustomLabel WHERE LanguageID = @0 AND ConnectorID is null", languageID).Select(c => new { c.MasterGroupMappingID, c.CustomLabel }).ToDictionary(c => c.MasterGroupMappingID, c => c.CustomLabel);

            var magentoLayouts       = _db.Query <MagentoPageLayout>("SELECT * FROM MagentoPageLayout").Select(c => new { c.LayoutID, c.LayoutCode }).ToDictionary(c => c.LayoutID, c => c.LayoutCode);
            var magentoSettingModels = _db.Query <MagentoProductGroupSetting>("SELECT * FROM MagentoProductGroupSetting WHERE MasterGroupMappingID is NOT NULL").ToList();
            var seoTextsModel        = new SortedList <int, List <SeoTexts> >(_db.Query <SeoTexts>("SELECT * FROM SeoTexts WHERE MasterGroupMappingID is NOT NULL").GroupBy(c => c.MasterGroupMappingID).ToDictionary(c => c.Key, c => c.ToList()));


            //refactor in a nicer way
            var presaleProducts = _db.Query <int>("select distinct productid from productattributevalue where attributeid in (select attributeid from productattributemetadata where attributecode= 'btf') and value = 'true'").ToList();

            presaleProducts.Sort();

            var supportsCompleteTheLookFunctionality = _db.FirstOrDefault <bool>("Select * from connectorsetting where connectorid = @0 and settingkey = 'CompleteTheLookConnector'", connectorID);

            var masterGroupMappingSettingsQuery = @";WITH OptionValues AS 
                                              (
                                                SELECT MGMS.MasterGroupMappingSettingID, MGMSV.MasterGroupMappingID, MGMSO.Value
                                                FROM MasterGroupMappingSetting MGMS
                                                INNER JOIN MasterGroupMappingSettingValue MGMSV ON MGMS.MasterGroupMappingSettingID = MGMSV.MasterGroupMappingSettingID
                                                INNER JOIN MasterGroupMappingSettingOption MGMSO ON MGMSV.Value = MGMSO.OptionID
                                                WHERE MGMS.Type = 'option'
                                              )
                                              SELECT MGMS.Name, MGMS.[Group], MGMS.[Type], MGMSV.MasterGroupMappingID
                                                , CASE WHEN OV.MasterGroupMappingSettingID IS NOT NULL THEN OV.Value ELSE MGMSV.Value END AS Value
                                              FROM MasterGroupMappingSettingValue MGMSV
                                              INNER JOIN MasterGroupMappingSetting MGMS ON MGMS.MasterGroupMappingSettingID = MGMSV.MasterGroupMappingSettingID
                                              INNER JOIN MasterGroupMapping MGM ON MGMSV.MasterGroupMappingID = MGM.MasterGroupMappingID
                                              LEFT JOIN OptionValues OV ON MGMS.MasterGroupMappingSettingID = OV.MasterGroupMappingSettingID AND MGMSV.MasterGroupMappingID = OV.MasterGroupMappingID
                                              WHERE MGM.ConnectorID = {0} {1}";

            var parentConnectorFilter = string.Empty;

            if (_connector.ParentConnectorID.HasValue)
            {
                parentConnectorFilter = string.Format("OR MGM.ConnectorID = {0}", _connector.ParentConnectorID);
            }

            var masterGroupMappingSettings           = _db.Query <MasterGroupMappingSettingResult>(string.Format(masterGroupMappingSettingsQuery, connectorID, parentConnectorFilter));
            var masterGroupMappingSettingsDictionary = new Dictionary <int, List <MasterGroupMappingSettingResult> >();

            foreach (var masterGroupMappingSetting in masterGroupMappingSettings)
            {
                if (!masterGroupMappingSettingsDictionary.ContainsKey(masterGroupMappingSetting.MasterGroupMappingID))
                {
                    masterGroupMappingSettingsDictionary.Add(masterGroupMappingSetting.MasterGroupMappingID, new List <MasterGroupMappingSettingResult>());
                }

                masterGroupMappingSettingsDictionary[masterGroupMappingSetting.MasterGroupMappingID].Add(masterGroupMappingSetting);
            }

            SynchronizedCollection <AssortmentProductInfo> assortmentList = new SynchronizedCollection <AssortmentProductInfo>();
            ParallelOptions options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 8
            };

#if DEBUG
            options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 8
            };
#endif

            Parallel.ForEach(Partitioner.Create(0, totalRecords), options, (range, loopState) =>
            {
                List <AssortmentProductInfo> list = new List <AssortmentProductInfo>();
                for (int idx = range.Item1; idx < range.Item2; idx++)
                {
                    var a = records[idx];

                    if (a.IsConfigurable)
                    {
                        var lis = relatedProductsList[a.ProductID].Where(c => c.IsConfigured).Select(c => c.RelatedProductID).ToList();

                        if (!records.Any(rp => lis.Contains(rp.ProductID)))
                        {
                            continue;
                        }
                    }

                    var productBarcodes = barcodes.Where(x => x.ProductID == a.ProductID).Select(c => c.Barcode).ToList();
                    var images          = productImages.Where(x => x.ProductID == a.ProductID).ToList();

                    var configAttributes = configAttributesList.ContainsKey(a.ProductID) ? configAttributesList[a.ProductID] : new List <ProductAttributeMetaData>();
                    var relatedProducts  = relatedProductsList.ContainsKey(a.ProductID) ? relatedProductsList[a.ProductID] : new List <RelatedProduct>();
                    if (supportsCompleteTheLookFunctionality)
                    {
                        if (a.IsConfigurable && a.ParentProductID != null)
                        {
                            //this is color level
                            //get from the relatedProductsList the ParentProduct related products.
                            var parentProductRelatedProducts = relatedProductsList.ContainsKey(a.ParentProductID.Value) ? relatedProductsList[a.ParentProductID.Value] : new List <RelatedProduct>();
                            parentProductRelatedProducts     = parentProductRelatedProducts.Where(c => c.RelatedProductTypeID == 9).ToList();

                            //foreach related product:
                            //if related product is artikel (IsConfigurable && ParentProductID == null) then find all colors of that artikel (get products where parentproductid is productid of artikel item)
                            //  the found color items are the related products.
                            //else
                            //  if related product is color level than this is the related product
                            foreach (var prp in parentProductRelatedProducts)
                            {
                                if (prp.PP_IsConfigurable && prp.PP_ParentProductID == null)
                                {
                                    //Is Artikel product
                                    var artikelRelatedProducts = relatedProductsList.ContainsKey(prp.ProductID)
                                                 ? relatedProductsList[prp.ProductID]
                                                 : new List <RelatedProduct>();

                                    //TODO: fix the types
                                    foreach (var rp in artikelRelatedProducts.Where(c => c.RelatedProductTypeID == 9 || c.RelatedProductTypeID == 10).ToList())
                                    {
                                        var colorItem            = relatedProductsList[rp.RelatedProductID].Where(t => t.RelatedProductTypeID == styleType.Key);
                                        var rangeRelatedProducts = (from ci in colorItem
                                                                    where !relatedProducts.Any(c => c.RelatedProductID == ci.RelatedProductID)
                                                                    select new RelatedProduct()
                                        {
                                            ProductID = a.ProductID,
                                            RelatedProductID = ci.RelatedProductID,
                                            RelatedProductTypeID = 9,
                                            Index = rp.Index,
                                            IsConfigured = false
                                        }).ToList();
                                        relatedProducts.AddRange(rangeRelatedProducts);
                                    }

                                    //relatedProducts.AddRange(artikelRelatedProducts.Distinct());
                                }
                                else
                                {
                                    relatedProducts.Add(prp);
                                }
                            }
                        }
                    }

                    var prices               = logic.CalculatePrice(a.ProductID);
                    var stockRetail          = logic.RetailStock(a.ProductID, _connector);
                    var productProductGroups = productGroups.ContainsKey(a.ProductID) ? productGroups[a.ProductID] : new List <ContentProductGroup>();

                    list.Add(new AssortmentProductInfo
                    {
                        Visible = a.Visible,
                        Content = new AssortmentContent()
                        {
                            ProductName      = !string.IsNullOrEmpty(a.ProductName.ToString()) ? a.ProductName.ToString() : a.ShortDescription,
                            ShortDescription = a.ShortDescription ?? string.Empty,
                            LongDescription  = a.LongDescription ?? string.Empty
                        },
                        ProductID           = a.ProductID,
                        ManufacturerID      = a.VendorItemNumber.Trim(),
                        IsNonAssortmentItem = a.IsNonAssortmentItem ?? false,
                        RelatedProducts     = (from rp in relatedProducts.Distinct().OrderBy(c => c.RelatedProductID)
                                               select new AssortmentRelatedProduct()
                        {
                            IsConfigured = rp.IsConfigured,
                            RelatedProductID = rp.RelatedProductID,
                            TypeID = rp.RelatedProductTypeID,
                            Type = relatedProductTypeList[rp.RelatedProductTypeID].Type,
                            Index = rp.Index,
                            MapsToMagentoTypeID = relatedProductTypeList[rp.RelatedProductTypeID].TypeMapsToMagentoTypeID
                        }).ToList(),

                        IsConfigurable  = a.IsConfigurable,
                        CustomProductID = a.CustomItemNumber,
                        PresaleProduct  = presaleProducts.Contains(a.ProductID),
                        Stock           = new AssortmentStock()
                        {
                            QuantityToReceive    = a.QuantityToReceive ?? 0,
                            InStock              = a.QuantityOnHand,
                            StockStatus          = a.ConnectorStatus,
                            PromisedDeliveryDate = a.PromisedDeliveryDate
                        },
                        RetailStock = (from rs in stockRetail.OrderBy(c => c.VendorStockTypeID)
                                       select new AssortmentRetailStock()
                        {
                            CostPrice = rs.UnitCost ?? 0,
                            VendorCode = rs.BackendVendorCode,
                            InStock = rs.QuantityOnHand,
                            StockStatus = mapper.GetForConnector(rs.ConcentratorStatusID),
                            Name = rs.VendorStockTypeID == 1 ? rs.vendorName : vendorstocktypes.Where(x => x.VendorStockTypeID == rs.VendorStockTypeID).Select(x => x.StockType).FirstOrDefault(),
                            PromisedDeliveryDate = rs.PromisedDeliveryDate,
                            QuantityToReceive = rs.QuantityToReceive ?? 0
                        }).ToList(),
                        Prices = (from p in prices.OrderBy(c => c.VendorAssortmentID)
                                  select new AssortmentPrice()
                        {
                            CommercialStatus = p.CommercialStatus,
                            CostPrice = p.CostPrice ?? 0,
                            SpecialPrice = p.SpecialPrice,
                            MinimumQuantity = p.MinimumQuantity ?? 0,
                            TaxRate = p.TaxRate ?? 19,
                            UnitPrice = p.Price
                        }).ToList(),
                        ConfigurableAttributes = (from ca in configAttributes
                                                  select new AssortmentConfigurableAttribute()
                        {
                            AttributeCode = ca.AttributeCode,
                            AttributeID = ca.AttributeID,
                            ConfigurablePosition = ca.ConfigurablePosition ?? 0
                        }).ToList(),
                        Barcodes = productBarcodes,
                        Images   = (from img in images.OrderBy(c => c.mediaid)
                                    select new AssortmentProductImage()
                        {
                            Sequence = img.Sequence ?? 0,
                            Path = img.ImagePath
                        }).ToList(),
                        Brand = GetAssortmentBrandHierarchy(a.BrandID, a.VendorBrandCode, brands),

                        ProductGroups =
                            (from p in productProductGroups.OrderBy(c => c.ContentProductGroupID)
                             select GetAssortmentProductGroupHierarchy(
                                 p.MasterGroupMappingID.Value


                                 , languageID
                                 , defaultLanguage.LanguageID


                                 , mappingslist
                                 , mappingMediaList
                                 , masterGroupMappingSettingsDictionary
                                 , productGroupNames
                                 , productGroupNamesDefault
                                 , productGroupDescriptions
                                 , productGroupCustomLabelsForThisConnector
                                 //, productGroupModels
                                 , magentoLayouts
                                 , magentoSettingModels
                                 , parentMappingList
                                 , productGroupCustomLabelsForDefaultConnector
                                 , seoTextsModel))
                            .ToList().OrderBy(x => x.Index).ToList()
                        ,
                        LineType = a.LineType
                        ,
                        ShopInfo = new AssortmentShopInformation()
                        {
                            LedgerClass         = a.LedgerClass,
                            ProductDesk         = a.ProductDesk,
                            ExtendedCatalog     = a.ExtendedCatalog ?? false,
                            OriginalLedgerClass = a.LedgerClass
                        },
                        DeliveryHours = a.DeliveryHours,
                        CutOffTime    = a.CutOffTime
                    });
                }

                foreach (var item in list)
                {
                    assortmentList.Add(item);
                }
            });
            return(assortmentList.Distinct().ToList());
        }