public AssociationViewModel(IViewModelsFactory<ISearchItemViewModel> searchVmFactory, Association item, IItemViewModel parent) { InnerItem = item; _searchVmFactory = searchVmFactory; AvailableAssociationTypes = new[] { AssociationTypes.optional.ToString(), AssociationTypes.required.ToString() }; ItemPickCommand = new DelegateCommand(RaiseItemPickInteractionRequest); CommonConfirmRequest = new InteractionRequest<Confirmation>(); }
private void RaiseItemEditInteractionRequest(Association originalItem) { var item = originalItem.DeepClone(_entityFactory as CatalogEntityFactory); if (RaiseItemEditInteractionRequest(item, "Edit association".Localize())) { // copy all values to original: OnUIThread(() => originalItem.InjectFrom<CloneInjection>(item)); // fake assign for UI triggers to display updated values. originalItem.ItemId = originalItem.ItemId; } }
public void Can_create_associationGroup_with_association() { var repository = GetRepository(); var items = new Item[] { }; CreateFullGraphCatalog(repository, ref items, "testcatalog"); //Refresh RefreshRepository(ref repository); var itemId = items[0].ItemId; var innerItem = repository.Items.Expand(x => x.AssociationGroups).Where(x => x.ItemId == itemId).Single(); // create AssociationGroup var ag = new AssociationGroup() { Name = "name" }; innerItem.AssociationGroups.Add(ag); // create Association itemId = items[1].ItemId; var a = new Association { AssociationType = "optional", //CatalogItem = repository.Items.Where(x => x.ItemId == itemId).Single() //USING THIS WORKS ONLY ON EF directly ItemId = itemId }; ag.Associations.Add(a); // save repository.UnitOfWork.Commit(); //RefreshClient RefreshRepository(ref repository); innerItem = repository.Items.Expand("AssociationGroups/Associations").Where(x => x.ItemId == innerItem.ItemId).Single(); ag = innerItem.AssociationGroups.Single(x => x.AssociationGroupId == ag.AssociationGroupId); Assert.NotNull(innerItem); Assert.True(innerItem.AssociationGroups.Any()); Assert.True(innerItem.AssociationGroups.Any(x => x.AssociationGroupId == ag.AssociationGroupId)); Assert.True(ag.Associations.Any()); Assert.True(ag.Associations.Any(x => x.AssociationId == a.AssociationId)); }
public void Can_delete_catalog_with_cascade() { var repository = GetRepository(); var items = new Item[] { }; const string catalogId = "testCatalog"; CreateFullGraphCatalog(repository, ref items, catalogId); // create an AssociationGroup var group = new AssociationGroup { Name = "Name", ItemId = items[0].ItemId }; repository.Add(group); var groupItem = new Association { AssociationType = "Required", AssociationGroupId = group.AssociationGroupId, ItemId = items[1].ItemId }; repository.Add(groupItem); repository.UnitOfWork.Commit(); RefreshRepository(ref repository); //var innerItem = repository.Catalogs.Where(x => x.CatalogId == catalogId).Single(); var innerItem = repository.Catalogs.OfType<Catalog>() .Where(x => x.CatalogId == catalogId) .Expand(x => x.CatalogLanguages) .Expand("PropertySets/PropertySetProperties/Property/PropertyValues") .SingleOrDefault(); repository.Remove(innerItem); repository.UnitOfWork.Commit(); var associationCount = repository.Associations.Count(); var itemCount = repository.Items.Count(); Assert.Equal(0, associationCount); Assert.Equal(0, itemCount); }
private void RaiseItemRemoveInteractionRequest(Association originalItem) { InnerItem.Associations.Remove(originalItem); }