public ProductDefectionsVM(ProductVM product, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentProduct = product;
            ProductDataService = new ProductDataService(UnitOfWork);
            ProductDataService.DefectionAdded += OnDefectionAdded;
            ProductDataService.DefectionRemoved += OnDefectionRemoved;
            DefectionDataService = new DefectionDataService(UnitOfWork);
            ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ProductDefectionVM>();
            foreach (var productDefection in ProductDataService.GetDefections(product.Id))
            {
                selectedVms.Add(new ProductDefectionVM(productDefection, Access, ProductDefectionDataService, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<DefectionVM>();
            foreach (var defection in DefectionDataService.GetActives(SoheilEntityType.Products, CurrentProduct.Id))
            {
                allVms.Add(new DefectionVM(defection, Access, DefectionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            IncludeRangeCommand = new Command(IncludeRange, CanIncludeRange);
            ExcludeRangeCommand = new Command(ExcludeRange, CanExcludeRange);
        }
Exemple #2
0
        private void OnProductAdded(object sender, ModelAddedEventArgs<Product> e)
        {
            var newContent = new ProductVM(e.NewModel, GroupItems, Access, ProductDataService, ProductGroupDataService);
            Items.AddNewItem(newContent);
            Items.CommitNew();

            CurrentContent = newContent;
            CurrentContent.IsSelected = true;
        }
 private void OnProductRemoved(object sender, ModelRemovedEventArgs e)
 {
     foreach (ProductDefectionVM item in SelectedItems)
     {
         if (item.Id == e.Id)
         {
             var model = ProductDataService.GetSingle(item.ProductId);
             var returnedVm = new ProductVM(model, Access, ProductDataService, ProductGroupDataService);
             AllItems.AddNewItem(returnedVm);
             AllItems.CommitNew();
             SelectedItems.Remove(item);
             break;
         }
     }
 }