public DefectionProductsVM(DefectionVM defection, AccessType access) : base(access) { UnitOfWork = new SoheilEdmContext(); CurrentDefection = defection; DefectionDataService = new DefectionDataService(UnitOfWork); DefectionDataService.ProductAdded += OnProductAdded; DefectionDataService.ProductRemoved += OnProductRemoved; ProductDataService = new ProductDataService(UnitOfWork); ProductGroupDataService = new ProductGroupDataService(UnitOfWork); ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork); var selectedVms = new ObservableCollection<ProductDefectionVM>(); foreach (var productDefection in DefectionDataService.GetProducts(defection.Id)) { selectedVms.Add(new ProductDefectionVM(productDefection, Access, ProductDefectionDataService, RelationDirection.Reverse)); } SelectedItems = new ListCollectionView(selectedVms); var allVms = new ObservableCollection<ProductVM>(); foreach (var product in ProductDataService.GetActives(SoheilEntityType.Defections, CurrentDefection.Id)) { allVms.Add(new ProductVM(product, Access, ProductDataService, ProductGroupDataService)); } AllItems = new ListCollectionView(allVms); IncludeCommand = new Command(Include, CanInclude); ExcludeCommand = new Command(Exclude, CanExclude); }
private void OnDefectionAdded(object sender, ModelAddedEventArgs<Defection> e) { var newDefectionVm = new DefectionVM(e.NewModel, Access, DefectionDataService); Items.AddNewItem(newDefectionVm); Items.CommitNew(); CurrentContent = newDefectionVm; CurrentContent.IsSelected = true; }
private void OnDefectionRemoved(object sender, ModelRemovedEventArgs e) { foreach (ProductDefectionVM item in SelectedItems) { if (item.Id == e.Id) { var model = DefectionDataService.GetSingle(item.DefectionId); var returnedVm = new DefectionVM(model, Access, DefectionDataService); AllItems.AddNewItem(returnedVm); AllItems.CommitNew(); SelectedItems.Remove(item); break; } } }