public virtual void AddDetailEntities()
        {
            var availalbleEntities      = DetailsRepository.ToList().Except(DetailEntities).ToArray();
            var selectEntitiesViewModel = new SelectDetailEntitiesViewModel <TDetailEntity>(availalbleEntities);

            if (DialogService.ShowDialog(MessageButton.OKCancel, CommonResources.AddRemoveDetailEntities_SelectObjects, selectEntitiesViewModel) == MessageResult.OK && selectEntitiesViewModel.SelectedEntities.Any())
            {
                foreach (var selectedEntity in selectEntitiesViewModel.SelectedEntities)
                {
                    DetailEntities.Add(selectedEntity);
                }
                SaveChangesAndNotify(selectEntitiesViewModel.SelectedEntities);
            }
        }
Esempio n. 2
0
        public override void AddDetailEntities()
        {
            var availableEntities       = DetailsRepository.ToList().Except(DetailEntities).ToArray();
            var selectEntitiesViewModel = new SelectDetailEntitiesViewModel <TDetailEntity>(availableEntities);

            if (DialogService.ShowDialog(MessageButton.OKCancel, CommonResources.AddRemoveDetailEntities_SelectObjects, selectEntitiesViewModel) == MessageResult.OK && selectEntitiesViewModel.SelectedEntities.Any())
            {
                foreach (var selectedEntity in selectEntitiesViewModel.SelectedEntities)
                {
                    var junction     = new TJunction();
                    var entityKey    = Repository.GetPrimaryKey(Entity);
                    var detailKey    = DetailsRepository.GetPrimaryKey(selectedEntity);
                    var junctionType = typeof(TJunction);
                    junctionType.GetProperty(ExpressionHelper.GetPropertyName(getEntityForeignKey)).SetValue(junction, entityKey, null);
                    junctionType.GetProperty(ExpressionHelper.GetPropertyName(getDetailForeignKey)).SetValue(junction, detailKey, null);
                    JunctionRepository.Add(junction);
                }
                SaveChangesAndNotify(selectEntitiesViewModel.SelectedEntities);
            }
        }