/// <summary> /// Initializes a new instance of the <see cref="ProductVM"/> class from the model. /// </summary> /// <param name="entity">The model.</param> /// <param name="access"></param> /// <param name="dataService"></param> public RootVM(Root entity, AccessType access, RootDataService dataService) : base(access) { InitializeData(dataService); _model = entity; if(entity.ProductDefection != null) CurrentProductDefection = new ProductDefectionVM(entity.ProductDefection, Access, ProductDefectionDataService, RelationDirection.Straight); FishbonesVM = new RootFishbonesVM(this, CurrentProductDefection, Access); }
private void OnDefectionAdded(object sender, ModelAddedEventArgs<ProductDefection> e) { var productDefectionVM = new ProductDefectionVM(e.NewModel, Access, ProductDefectionDataService, RelationDirection.Straight); SelectedItems.AddNewItem(productDefectionVM); SelectedItems.CommitNew(); foreach (IEntityItem item in AllItems) { if (item.Id == productDefectionVM.DefectionId) { AllItems.Remove(item); break; } } }
public RootFishbonesVM(RootVM root, ProductDefectionVM productDefection, AccessType access) : base(access) { UnitOfWork = new SoheilEdmContext(); CurrentRoot = root; RootDataService = new RootDataService(UnitOfWork); RootDataService.FishboneAdded += OnFishboneNodeAdded; RootDataService.FishboneRemoved += OnFishboneNodeRemoved; ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork); ProductDataService = new ProductDataService(UnitOfWork); DefectionDataService = new DefectionDataService(UnitOfWork); SwitchItemsCommand = new Command(SetProductDefections); ViewProductDefectionsCommand = new Command(ViewProductDefections); InitializeFishboneCommand = new Command(InitializeFishbone); FishboneNodeDataService = new FishboneNodeDataService(UnitOfWork); RootNode = new FishboneNodeVM(Access, FishboneNodeDataService) { Title = string.Empty, Id = -1, ParentId = -2 }; var selectedVms = new ObservableCollection<FishboneNodeVM>(); foreach (var rootFishboneNode in RootDataService.GetFishboneNodes(root.Id)) { selectedVms.Add(new FishboneNodeVM(rootFishboneNode, Access, FishboneNodeDataService)); } SetProductDefections(); IncludeCommand = new Command(Include, CanInclude); ExcludeTreeCommand = new Command(ExcludeTree, CanExcludeTree); foreach (FishboneNodeVM item in selectedVms) { if (item.ParentId == RootNode.Id) { RootNode.ChildNodes.Add(item); break; } } CurrentNode = RootNode; if (productDefection != null) { foreach (IInfoViewModel item in DefectionList) { if (item.Id == productDefection.DefectionId) { CurrentDefection = item; ViewProductDefections(null); break; } } if(AllItems!=null) foreach (ProductDefectionVM item in AllItems) { if (item.Id == productDefection.Id) { CurrentProductDefection = item; IsEnabled = false; break; } } } }