public DrmControlViewModel() { AddSetterPropertiesTrigger(new PropertiesTrigger(() => { var currentModel = GenericManager.Model; Entities = GenericManager.Model.Entities.OrderBy(k => k.DisplayName).ToList(); Relationships = GenericManager.Model.Relationships; CurrentViewType = ViewType.List; CurrentEntity = !string.IsNullOrEmpty(currentModel.MainEntity) ? Entities.First(k => k.LogicalName == currentModel.MainEntity) : Entities.First(); }, nameof(GenericManager))); GenericEventManager = new GenericEventManager(); GenericEventManager.OnCreateRequested += BusinessEventManager_OnCreateRequested; GenericEventManager.OnCreatedEntity += GenericEventManager_OnCreatedEntity; GenericEventManager.OnUpdatedEntity += BusinessEventManager_OnUpdatedEntity; GenericEventManager.OnSelectedEntity += BusinessEventManager_OnSelectedEntity; GenericEventManager.OnDeletedEntity += BusinessEventManager_OnDeletedEntity; WpfEventManager = new WpfEventManager(); WpfEventManager.OnEntityReferenceInputLeftClicked += WpfEventManager_OnEntityReferenceInputLeftClicked; WpfEventManager.OnCustomModuleEditingRequest += WpfEventManager_OnCustomModuleEditingRequest; InitializeCommands(); }
private void InitializeCommands() { SaveCommand = new RelayCommandHandled((data) => { if (Mode == DetailMode.Creating) { var id = GenericManager.Create(Entity.LogicalName, Values); //var newData = GenericManager.Retrieve(Entity.LogicalName, id); //Id = id; //Values = newData.Values; //Mode = DetailMode.Updating; GenericEventManager.RaiseOnCreatedEntity(Entity, id); } else if (Mode == DetailMode.Updating) { GenericManager.Update(Entity.LogicalName, Id, Values); GenericEventManager.RaiseOnUpdatedEntity(Entity, Id, Values); } }, (data) => { return(IsCompleted); }); DeleteCommand = new RelayCommandHandled((data) => { var dialog = new OkCancelMessageBox("Confirm the delete? This operation cannot be undone", "Delete operation"); dialog.ShowDialog(); if (dialog.Response == OkCancelMessageBox.InputTextBoxResponse.OK) { GenericManager.Delete(Entity.LogicalName, Id); GenericEventManager.RaiseOnDeletedEntity(Entity, Id); } }, (data) => { return(Mode == DetailMode.Updating); }); RegisterCommand(SaveCommand); RegisterCommand(DeleteCommand); }
private void InitializeCommands() { CreateCommand = new RelayCommandHandled((data) => { GenericEventManager.RaiseOnCreateRequested(Entity); }); AddNewRelatedCommand = new RelayCommandHandled((data) => { var initialValues = new Dictionary <string, object>(); initialValues.Add(FilterRelationship.RelatedAttribute, new EntityReferenceValue() { Id = FilterRelationshipId, LogicalName = FilterRelationship.RelatedEntity, DisplayName = FilterRelationshipRecordDisplayName, }); GenericEventManager.RaiseOnCreateRequested(Entity, initialValues); }); AssociateCommand = new RelayCommandHandled((data) => { var availableValues = GenericManager.RetrieveAll(FirstEntityAssociation); var availablesEntityReferences = availableValues .Values .Select(k => new EntityReferenceValue() { Id = k.Id, LogicalName = FirstEntityAssociation, DisplayName = (string)k.Values["Name"] }) .ToList(); var initialEntityReferences = DataSetModel .Values .Select(k => new EntityReferenceValue() { Id = k.Id, LogicalName = FirstEntityAssociation, DisplayName = (string)k.Values["Name"] }) .ToList(); var associateWindow = new MultipleAssociationWindow( $"Associate {FirstEntityAssociation}(s) to this {SecondEntityAssociation}", "Association", availablesEntityReferences, initialEntityReferences); associateWindow.ShowDialog(); var response = associateWindow.Response; if (response == MultipleAssociationWindow.MultipleAssociationResponse.OK) { var firstRecordEntityLogicalName = Entity.LogicalName; var secondRecordEntityLogicalName = firstRecordEntityLogicalName == FilterRelationship.MainEntity ? FilterRelationship.RelatedEntity : FilterRelationship.MainEntity; var selectedValues = associateWindow.SelectedValues; foreach (var item in initialEntityReferences) { GenericManager.Disassociate(secondRecordEntityLogicalName, FilterRelationshipId, FilterRelationship.IntersectionName, firstRecordEntityLogicalName, item.Id); } foreach (var item in selectedValues) { GenericManager.Associate(secondRecordEntityLogicalName, FilterRelationshipId, FilterRelationship.IntersectionName, firstRecordEntityLogicalName, item.Id); } GetValues(); } }); RegisterCommand(AddNewRelatedCommand); RegisterCommand(CreateCommand); RegisterCommand(AssociateCommand); }
public void SelectedDataRow(DataRecord dataRowModel) { GenericEventManager.RaiseOnSelectedEntity(Entity, dataRowModel.Id); }
private void WpfEventManager_OnEntityReferenceInputLeftClicked(object sender, Wpf.Events.WpfEntityReferenceClickEventArgs args) { GenericEventManager.RaiseOnSelectedEntity(Entities.First(k => k.LogicalName == args.EntityLogicalName), args.Id); }