public bool CallBack(Cargo cargo) { if (cargo != null) { bool IsExist = CargoViewModels.Any <CargoViewModel> (item => item.Cargo.PreciseCargoName == cargo.PreciseCargoName); if (!IsExist) { CargoViewModel cargoViewModel = new CargoViewModel(CMContext); cargoViewModel.Cargo = cargo; cargoViewModel.CargoViewModels = CargoViewModels; cargoViewModel.CargoCollectionViewModels = CargoCollectionViewModels; CMContext.Cargo.Add(cargo); CMContext.SaveChanges(); CargoViewModels.Add(cargoViewModel); return(false); } else { return(true); } } else { return(false); } }
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); } }