예제 #1
0
        public async Task <IActionResult> Sell([FromBody] SellOrderViewModel model)
        {
            var userClaims = _caller.Claims.Single(c => c.Type == "id");
            var user       = mongoRepositoryUserInfo.Where(u => u.Username == userClaims.Value).FirstOrDefault();
            var address    = this.nethereumService.GetPublicAddress(user.PrivateKey);
            var order      = new Order()
            {
                TransactionId = Guid.NewGuid().ToString(),
                Amount        = model.Amount,
                Price         = model.Price,
                Seller        = address
            };
            var tx = await this.nethereumService.CreateOrder(user.PrivateKey, order.TransactionId, order.Amount, order.Price);

            order.TransactionBlockchain = tx;
            mongoRepositoryOrder.Add(order);
            return(new OkObjectResult(tx));
        }
        private void InitializeViewModels()
        {
            WarehouseRootViewModel = new WarehouseRootViewModel(CMContext);
            foreach (var warehouse in CMContext.Warehouse.Local)
            {
                WarehouseViewModel bufferWarehouseViewModel = new WarehouseViewModel(CMContext);
                bufferWarehouseViewModel.Warehouse = warehouse;
                foreach (var plane in warehouse.Planes)
                {
                    PlaneViewModel bufferPlaneViewModel = new PlaneViewModel(CMContext);
                    bufferPlaneViewModel.Plane = plane;
                    foreach (var block in plane.Blocks)
                    {
                        BlockViewModel bufferBlockViewModel = new BlockViewModel(CMContext);
                        bufferBlockViewModel.Block = block;
                        foreach (var cargoCollection in block.CargoCollections)
                        {
                            CargoCollectionViewModel bufferCargoCollectionViewModel = new CargoCollectionViewModel(CMContext)
                            {
                                CargoCollectionViewModels = CargoCollectionViewModels
                            };
                            bufferCargoCollectionViewModel.CargoCollection           = cargoCollection;
                            bufferCargoCollectionViewModel.BlockViewModel            = bufferBlockViewModel;
                            bufferCargoCollectionViewModel.SelectedPurchasePrizeDic  = bufferCargoCollectionViewModel.CargoCollection.PurchasePrizeDics[0];
                            bufferCargoCollectionViewModel.CargoCollectionViewModels = CargoCollectionViewModels;

                            bufferBlockViewModel.CargoCollectionViewModels.Add(bufferCargoCollectionViewModel);
                            CargoCollectionViewModels.Add(bufferCargoCollectionViewModel);
                        }
                        bufferBlockViewModel.PlaneViewModel = bufferPlaneViewModel;
                        bufferPlaneViewModel.BlockViewModels.Add(bufferBlockViewModel);
                    }
                    bufferPlaneViewModel.WarehouseViewModel = bufferWarehouseViewModel;
                    bufferWarehouseViewModel.PlaneViewModels.Add(bufferPlaneViewModel);
                }
                bufferWarehouseViewModel.WarehouseRootViewModel = WarehouseRootViewModel;
                WarehouseRootViewModel.WarehouseViewModels.Add(bufferWarehouseViewModel);
            }
            foreach (var cargo in CMContext.Cargo.Local)
            {
                CargoViewModel bufferCargoViewModel = new CargoViewModel(CMContext);
                bufferCargoViewModel.Cargo                     = cargo;
                bufferCargoViewModel.CargoViewModels           = CargoViewModels;
                bufferCargoViewModel.CargoCollectionViewModels = CargoCollectionViewModels;
                CargoViewModels.Add(bufferCargoViewModel);
            }
            PurchaseOrderCollectionViewModels = new ObservableCollection <PurchaseOrderCollectionViewModel>();
            foreach (var purchaseOrderCollection in CMContext.PurchaseOrderCollection.Local)
            {
                PurchaseOrderCollectionViewModel pocvm = new PurchaseOrderCollectionViewModel(CMContext)
                {
                    PurchaseOrderCollection = purchaseOrderCollection, PurchaseOrderCollectionViewModels = PurchaseOrderCollectionViewModels
                };
                foreach (var purchaseOrder in purchaseOrderCollection.PurchaseOrders)
                {
                    PurchaseOrderViewModel povm = new PurchaseOrderViewModel(CMContext)
                    {
                        PurchaseOrder = purchaseOrder, PurchaseOrderCollectionViewModel = pocvm
                    };
                    pocvm.PurchaseOrderViewModels.Add(povm);
                }
                PurchaseOrderCollectionViewModels.Add(pocvm);
            }
            SellOrderCollectionViewModels = new ObservableCollection <SellOrderCollectionViewModel>();
            foreach (var sellOrderCollection in CMContext.SellOrderCollection.Local)
            {
                SellOrderCollectionViewModel socvm = new SellOrderCollectionViewModel(CMContext)
                {
                    SellOrderCollection = sellOrderCollection, SellOrderCollectionViewModels = SellOrderCollectionViewModels
                };
                foreach (var sellOrder in sellOrderCollection.SellOrders)
                {
                    SellOrderViewModel sovm = new SellOrderViewModel(CMContext, new CargoCollectionViewModel())
                    {
                        SellOrder = sellOrder
                    };
                    socvm.SellOrderViewModels.Add(sovm);
                }
                SellOrderCollectionViewModels.Add(socvm);
            }
        }