Exemple #1
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Include <OrderEntity>()
            .WithQuery(() => o => new
            {
                Entity = o,
                o.Id,
                o.State,
                o.Customer,
                o.Employee,
                o.OrderDate,
                o.RequiredDate,
                o.ShipAddress,
                o.ShipVia,
            });

            QueryLogic.Queries.Register(OrderQuery.OrderLines, () =>
                                        from o in Database.Query <OrderEntity>()
                                        from od in o.Details
                                        select new
            {
                Entity = o,
                o.Id,
                od.Product,
                od.Quantity,
                od.UnitPrice,
                od.Discount,
                od.SubTotalPrice,
            });

            OrderGraph.Register();

            ProcessLogic.Register(OrderProcess.CancelOrders, new CancelOrderAlgorithm());

            SimpleTaskLogic.Register(OrderTask.CancelOldOrdersWithProcess, ctx =>
            {
                var package = new PackageEntity().CreateLines(Database.Query <OrderEntity>().Where(a => a.OrderDate < DateTime.Now.AddDays(-7) && a.State != OrderState.Canceled));

                var process = ProcessLogic.Create(OrderProcess.CancelOrders, package);

                process.Execute(ProcessOperation.Execute);

                return(process.ToLite());
            });

            SimpleTaskLogic.Register(OrderTask.CancelOldOrders, ctx =>
            {
                Database.Query <OrderEntity>()
                .Where(a => a.OrderDate < DateTime.Now.AddDays(-7))
                .UnsafeUpdate()
                .Set(o => o.CancelationDate, o => DateTime.Now)
                .Set(o => o.State, o => OrderState.Canceled)
                .Execute();

                return(null);
            });//CancelOldOrdersProcess
        }
    }
        public OrderGraph ConvertOrderGraph(List <dynamic[]> collection)
        {
            var graph = new OrderGraph {
                Orders = new List <OrderGraphItem>()
            };

            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (collection.Count == 0)
            {
                return(graph);
            }

            var tempCount = 0;
            var list      = collection.Select(
                x =>
            {
                var item = new OrderGraphItem
                {
                    Count = (int)x[1] - tempCount, Price = (double)x[0], Title = (string)x[2]
                };
                tempCount = item.Count;
                return(item);
            }).ToList();

            graph.Orders = list;
            graph.Total  = (int)collection.Last()[1];

            return(graph);
        }