public override async Task<bool> InvokeAsync(string paramList)
{
var shipperCities = new[]
{
"Guadalajara, JAL, Mexico", "Los Angeles, CA, USA", "Portland, OR, USA", "Leon, GTO, Mexico",
"Boston, MA, USA"
};
var companies = new[]
{
"Unosquare LLC", "Advanced Technology Systems", "Super La Playa", "Vesta", "Microsoft", "Oxxo",
"Simian"
};
var rand = new Random();
var products = _context.Products.ToArray();
var order = new Order
{
CustomerName = companies[rand.Next(companies.Length - 1)],
IsShipped = rand.Next(10) > 5,
ShipperCity = shipperCities[rand.Next(shipperCities.Length - 1)],
ShippedDate = DateTime.Now.AddDays(1 - rand.Next(10)),
OrderType = rand.Next(30),
Amount = 10
};
//for (var k = 0; k < rand.Next(10); k++)
//{
// order.Details.Add(new OrderDetail
// {
// Price = rand.Next(10),
// Description = "Product ID" + rand.Next(1000),
// Quantity = rand.Next(10),
// ProductID = products[rand.Next(products.Length - 1)].ProductID
// });
//}
// order.Amount = order.Details.Sum(x => x.Price*x.Quantity);
OutputInformation("OrderID {0}", order.OrderID);
OutputInformation("OrderType {0}", order.OrderType);
OutputInformation("ShippedDate {0}", order.ShippedDate);
OutputInformation("ShipperCity {0}", order.ShipperCity);
_context.Orders.Add(order);
_context.SaveChanges();
OutputInformation("After save");
OutputInformation("OrderID {0}", order.OrderID);
OutputInformation("OrderType {0}", order.OrderType);
OutputInformation("ShippedDate {0}", order.ShippedDate);
OutputInformation("ShipperCity {0}", order.ShipperCity);
return true;
}
}