private void SkewPricesAndInventory()
        {
            Random pRandom = new Random();


            //mobile specific - pricing and inventory incongruities
            var mProducts = db.Products.ToList();

            foreach (var p in mProducts)
            {
                var newPrice = p.Price / 100 * (pRandom.Next(100, 200));
                if (newPrice <= 0.00M)
                {
                    newPrice = 5.00M;
                }
                if (newPrice >= 500.00M)
                {
                    newPrice = 500.00M;
                }
                p.Inventory = pRandom.Next(1, 100);
                p.LeadTime  = pRandom.Next(0, 14);
                p.Price     = newPrice;
                p.SalePrice = newPrice * .85M;
            }
            db.SaveChanges();
        }
Beispiel #2
0
        public static void CreateOrderProcessTask([Queue("orders")] CloudQueue orderQueue)
        {
            Console.WriteLine("Starting Create Order Process Task");
            try
            {
                var builder = new ConfigurationBuilder();
                builder.Add(new JsonConfigurationSource("config.json"));
                var config           = builder.Build();
                var connectionString = config["Data:DefaultConnection:ConnectionString"];

                using (var context = new PartsUnlimitedContext(connectionString))
                {
                    var orders = context.Orders.Where(x => !x.Processed).ToList();
                    Console.WriteLine("Found {0} orders to process", orders.Count);

                    foreach (var order in orders)
                    {
                        var productIds = context.OrderDetails.Where(x => x.OrderId == order.OrderId).Select(x => x.ProductId).ToList();
                        var items      = context.Products
                                         .Where(x => productIds.Contains(x.ProductId))
                                         .ToList();

                        var orderItems = items.Select(
                            x => new LegacyOrderItem
                        {
                            SkuNumber = x.SkuNumber,
                            Price     = x.Price
                        }).ToList();

                        var queueOrder = new LegacyOrder
                        {
                            Address      = order.Address,
                            Country      = order.Country,
                            City         = order.City,
                            Phone        = order.Phone,
                            CustomerName = order.Name,
                            OrderDate    = order.OrderDate,
                            PostalCode   = order.PostalCode,
                            State        = order.State,
                            TotalCost    = order.Total,
                            Discount     = order.Total,
                            Items        = orderItems
                        };
                        var settings = new JsonSerializerSettings {
                            ContractResolver = new CamelCasePropertyNamesContractResolver()
                        };
                        var message = JsonConvert.SerializeObject(queueOrder, settings);
                        orderQueue.AddMessage(new CloudQueueMessage(message));
                        order.Processed = true;
                    }
                    context.SaveChanges();
                    Console.WriteLine("Orders successfully processed.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public static void CreateOrderProcessTask([Queue("orders")] CloudQueue orderQueue)
        {
            Console.WriteLine("Starting Create Order Process Task");
            try
            {
                var builder = new ConfigurationBuilder();
                //builder.Add(new JsonConfigurationSource("config.json"));
                builder.AddJsonFile("config.json");
                var config = builder.Build();
                var connectionString = config["Data:DefaultConnection:ConnectionString"];

                using (var context = new PartsUnlimitedContext(connectionString))
                {
                    var orders = context.Orders.Where(x => !x.Processed).ToList();
                    Console.WriteLine("Found {0} orders to process", orders.Count);

                    foreach (var order in orders)
                    {
                        var productIds = context.OrderDetails.Where(x => x.OrderId == order.OrderId).Select(x => x.ProductId).ToList();
                        var items = context.Products
                            .Where(x => productIds.Contains(x.ProductId))
                            .ToList();

                        var orderItems = items.Select(
                                x => new LegacyOrderItem
                                {
                                    SkuNumber = x.SkuNumber,
                                    Price = x.Price
                                }).ToList();

                        var queueOrder = new LegacyOrder
                        {
                            Address = order.Address,
                            Country = order.Country,
                            City = order.City,
                            Phone = order.Phone,
                            CustomerName = order.Name,
                            OrderDate = order.OrderDate,
                            PostalCode = order.PostalCode,
                            State = order.State,
                            TotalCost = order.Total,
                            Discount = order.Total,
                            Items = orderItems
                        };
                        var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
                        var message = JsonConvert.SerializeObject(queueOrder, settings);
                        orderQueue.AddMessage(new CloudQueueMessage(message));
                        order.Processed = true;
                    }
                    context.SaveChanges();
                    Console.WriteLine("Orders successfully processed.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }