Exemple #1
0
        public static void UpdateOrdersDate()
        {
            DateTime time = Database.Query<OrderEntity>().Max(a => a.OrderDate);

            var now = TimeZoneManager.Now;
            var ts = (int)(now - time).TotalDays;

            ts = (ts / 7) * 7;

            Database.Query<OrderEntity>().UnsafeUpdate()
                .Set(o => o.OrderDate, o => o.OrderDate.AddDays(ts))
                .Set(o => o.ShippedDate, o => o.ShippedDate.Value.AddDays(ts))
                .Set(o => o.RequiredDate, o => o.RequiredDate.AddDays(ts))
                .Set(o => o.CancelationDate, o => null)
                .Execute();


            var limit = TimeZoneManager.Now.AddDays(-10);

            var list = Database.Query<OrderEntity>().Where(a => a.State == OrderState.Shipped && a.OrderDate < limit).Select(a => a.ToLite()).ToList();

            Random r = new Random(1);

            for (int i = 0; i < list.Count * 0.1f; i++)
            {
                r.NextElement(list).InDB().UnsafeUpdate()
                .Set(o => o.ShippedDate, o => null)
                .Set(o => o.CancelationDate, o => o.OrderDate.AddDays((int)o.Id % 10))
                .Set(o => o.State, o => OrderState.Canceled)
                .Execute();
            }
        }
 private static AddressEntity RandomAddress(int seed)
 {
     Random r = new Random(seed);
     return new AddressEntity
     {
         Address = r.NextElement(new[] { "Madison Av.", "Sessame Str.", "5th Av.", "Flamingo Way" }) + " " + r.Next(100),
         City = r.NextElement(new[] { "New York", "Los Angeles", "Miami", "Seattle" }),
         Country = "USA",
         Region = r.NextElement(new[] { "NY", "FL", "WA", "CA" }),
         PostalCode = r.NextString(5, "0123456789")
     };
 }