Exemplo n.º 1
0
        public async Task <IActionResult> RemoveAllInOrderItemList([FromBody] RemoveAllCommand command)
        {
            if (command == null)
            {
                return(await Respond(null, new List <Notification> {
                    new Notification("Order", "Parameters is invalid.")
                }));
            }

            var result = _orderCommandHandler.Handle(command);

            return(await Respond(result, _orderCommandHandler.Notifications));
        }
        public ICommandResult Handle(RemoveAllCommand command)
        {
            var order = _orderAdoRepository.GetLastCreatedOrderById(command.OrderId);

            if (order == null)
            {
                AddNotification("Order", "Order isn't found.");
            }

            if (Invalid)
            {
                return(null);
            }

            _orderItemAdoRepository.DeleteAllbyOrderId(command.OrderId);

            return(new ReturnedItemCommandResult(order.Id));
        }
Exemplo n.º 3
0
        private async void CreateOrderExecute()
        {
            Order  newOrder    = new Order();
            string shipCountry = "USA";

            newOrder.CustomerID  = SelectedCustomer.CustomerID;
            newOrder.EmployeeID  = SelectedEmployee.EmployeeID;
            newOrder.OrderDate   = DateTime.Parse(OrderDate);
            newOrder.ShipCountry = shipCountry;

            ProductsInOrder.ForEach(productInOrder => productInOrder.IsSaled = true);

            var orderDetails = ProductsInOrder.Select(p => new Order_Detail
            {
                ProductID = p.ProductID,
                UnitPrice = (decimal)p.UnitPrice,
                Quantity  = (short)p.SelectedQuantity,
                Discount  = p.SelectedDiscount / 100
            }).ToList();

            await northwindRepository.AddOrder(newOrder, orderDetails);

            int id = (await northwindRepository.GetOrders()).Last().OrderID;

            RemoveAllCommand.Execute().Subscribe();

            productsInOrder.Clear();
            OrderDate        = String.Empty;
            SelectedCustomer = null;
            SelectedEmployee = null;

            MessageBus.Current.SendMessage <NewOrderCreated>(new NewOrderCreated()
            {
                OrderId = id
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// 处理执行完毕的命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskScheduler_Executed(object sender, EventArgs e)
        {
            TaskScheduler sch = sender as TaskScheduler;

            if (sch == null)
            {
                Debug.Fail("TaskScheduler_Executed(), sender == null");
            }
            AddLog("TC: " + sch.Tasks.Count);
            Task   at = sch.ActiveTask;
            string s  = string.Format("send: {0}, {1}\r\nrece: {2}, {3}",
                                      at.LastSendDateTime, CT.BytesToString(at.LastSendDatas),
                                      at.LastReceivedDateTime, CT.BytesToString(at.LastReceived));

            AddLog(s);
            s = at.LastCommResultState.ToString();
            AddLog(s);
            CommCmdBase cmd = sch.ActiveTask.CommCmd;

            // read total count cmd
            //
            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand c = cmd as ReadTotalCountCommand;

                AddLog("LocalTotalCount: " + c.TotalCount);
                AddLog(c.Station.StationName + c.Station.Address);

                // need read all record and clear xg ctrler data
                //
                if (at.Tag != null)
                {//&&
                    // (string)at.Tag == TagType.OP_ReadAndClearXgData.ToString() )
                    //{
                    object[] tags    = (object[])at.Tag;
                    TagType  tagType = (TagType)tags[0];
                    XGTask   xgtask  = (XGTask)tags[1];

                    RemoveAllCommand clearCmd  = new RemoveAllCommand(c.Station as XGStation);
                    Task             clearTask = new Task(clearCmd, new ImmediateTaskStrategy());
                    Singles.S.TaskScheduler.Tasks.Add(clearTask);

                    for (int i = 0; i < c.TotalCount; i++)
                    {
                        ReadRecordCommand rdcmd = new ReadRecordCommand(c.Station as XGStation, i + 1);
                        Task t = new Task(rdcmd, new ImmediateTaskStrategy());
                        Singles.S.TaskScheduler.Tasks.Add(t);
                    }

                    // ???
                    //
                    //RemoveAllCommand rac = new RemoveAllCommand( c.Station as XGStation );
                    //Task trac = new Task( "rdall", rac, new ImmediateTaskStrategy() );
                    //trac.Tag = xgtask;
                    //trac.BeforeExecuteTask +=new EventHandler(trac_BeforeExecuteTask);
                    //Singles.S.TaskScheduler.Tasks.Add( trac );
                }
            }

            // read record cmd
            //
            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand rdcmd = cmd as ReadRecordCommand;
                AddLog("record index: " + rdcmd.RecordIndex);

                if (rdcmd.XGData != null)
                {
                    // 2007.03.11 Modify
                    //
                    //XGDB.InsertXGData( rdcmd.XGData );
                    XGDB.InsertXGData(cmd.Station.DestinationIP, rdcmd.XGData);
                }

                XGTask[] tasks = Singles.S.XGScheduler.Tasks.MatchXGData(rdcmd.XGData);
                foreach (XGTask task in tasks)
                {
                    task.IsComplete = true;
                }
            }
        }