Example #1
0
        public override void Execute(ISession session)
        {
            Console.Write("Код для соответствия:");
            var value        = Console.ReadLine();
            var user         = User(session);
            var priceId      = user.Client.Settings.SmartOrderRule.AssortmentPriceCode;
            var intersection = session.Query <TestIntersection>()
                               .FirstOrDefault(i => i.Price.Id == priceId && i.Client == user.Client);

            if (intersection == null)
            {
                intersection = new TestIntersection {
                    Price       = session.Load <TestPrice>(priceId),
                    Client      = user.Client,
                    Region      = user.Client.HomeRegion,
                    LegalEntity = user.AvaliableAddresses[0].LegalEntity
                };
                intersection.AddressIntersections.Add(new TestAddressIntersection(user.AvaliableAddresses[0], intersection));
                session.Save(intersection);
                session.SaveEach(intersection.AddressIntersections);
            }
            var addressIntersection = intersection.AddressIntersections.First(a => a.Address == user.AvaliableAddresses[0]);

            addressIntersection.SupplierDeliveryId = value;
        }
Example #2
0
        public override void Execute(ISession session)
        {
            var user = User(session);

            if (Verbose && ProductIds.Length == 0)
            {
                ProductIds = session.Query <TestCore>().Select(o => o.Product.Id).Distinct().Take(5).ToArray();
                var root = DbHelper.GetRoot();
                var file = Path.Combine(root, "src", "data", "smart-order.txt");
                File.WriteAllText(file, ProductIds.Implode(v => String.Format("{0}|1", ProductIds.IndexOf(v) + 1), Environment.NewLine));
                Console.WriteLine("Соответствие продуктов кодам");
                foreach (var productId in ProductIds)
                {
                    Console.WriteLine("{0} -> {1}", session.Load <TestProduct>(productId).FullName, ProductIds.IndexOf(productId) + 1);
                }
                Console.WriteLine("Тестовая дефектура - {0}", FileHelper.RelativeTo(file, root));
            }

            var supplier = TestSupplier.CreateNaked(session, TestRegion.Inforoom);
            var price    = supplier.Prices[0];

            price.PriceType = PriceType.Assortment;
            for (var i = 0; i < ProductIds.Length; i++)
            {
                var product = session.Load <TestProduct>(ProductIds[i]);
                price.Core.Add(new TestCore(price.AddProductSynonym(product.FullName, product))
                {
                    Code = (i + 1).ToString(), Period = "", Quantity = "", Product = product
                });
            }
            foreach (var tuple in SynonymMap)
            {
                price.AddProductSynonym(tuple.Item1, session.Load <TestProduct>(tuple.Item2));
            }
            foreach (var tuple in AddressMap)
            {
                var address             = session.Load <TestAddress>(tuple.Item2);
                var addressIntersection = session.Query <TestAddressIntersection>()
                                          .FirstOrDefault(i => i.Intersection.Price == supplier.Prices[0] && i.Address == address);
                if (addressIntersection == null)
                {
                    var intersection = new TestIntersection(supplier.Prices[0], address.Client);
                    session.Save(intersection);
                    session.Refresh(intersection);
                    addressIntersection = intersection.AddressIntersections.First(i => i.Address == address);
                }
                addressIntersection.SupplierDeliveryId = tuple.Item1;
            }
            session.Save(supplier);
            Rule.AssortmentPriceCode = price.Id;
            user.Client.Settings.EnableSmartOrder = true;
            user.Client.Settings.SmartOrderRule   = Rule;
            session.Save(user);
        }
        private void SetSupplierAndClientConnection(int numberOfSuppliers = 1, bool sameRegion = true)
        {
            supplierList = new Dictionary <TestSupplier, int>();
            //новый клиент
            client      = TestClient.CreateNaked(session, 2, 2);
            recipientId = new Random().Next(100000, 999999);
            for (int i = 0; i < numberOfSuppliers; i++)
            {
                //новый поставщик
                supplier = TestSupplier.CreateNaked(session);
                //настройка для отправки почты
                var source = supplier.Prices[0].Costs[0].PriceItem.Source;
                source.SourceType = PriceSourceType.Email;
                source.EmailTo    = $"to_{supplier.Id}@sup.com";
                source.EmailFrom  = $"from_{supplier.Id}@sup.com";

                //связь с клиентом ->>
                if (sameRegion)
                {
                    supplier.RegionMask = client.MaskRegion;
                }
                session.Save(supplier);
                while (recipientId != new Random().Next(100000, 999999))
                {
                    recipientId = new Random().Next(100000, 999999);
                }
                var prices       = supplier.Prices.FirstOrDefault();
                var intersection = new TestIntersection(prices, client);
                aIntersection      = new TestAddressIntersection(client.Addresses.FirstOrDefault(), intersection);
                intersection.Price = prices;
                aIntersection.SupplierDeliveryId = recipientId.ToString();
                session.Save(intersection);
                session.Save(aIntersection);
                session.Flush();
                //<<- связь с клиентом |

                supplierList.Add(supplier, recipientId);
            }
        }