Inheritance: IEntityViewButton
Example #1
0
        protected virtual Task <EntityViewModel <TEntity> > GetMultipleSelectorModel(IQueryable <TEntity> queryable)
        {
            return(Task.Run <EntityViewModel <TEntity> >(() =>
            {
                EntityViewModel <TEntity> model = new EntityViewModel <TEntity>(queryable, 1, 20);
                model.Headers = Metadata.ViewProperties;

                EntityViewButton cancelButton = new EntityViewButton();
                cancelButton.Name = "Cancel";
                cancelButton.GetInvokeDelegate = new EntityViewButtonCommandDelegate(viewer =>
                {
                    return new Task(() =>
                    {
                        viewer.Dispatcher.Invoke(() => viewer.DialogResult = false);
                    });
                });
                model.ViewButtons = new IViewButton[] { cancelButton };

                EntityItemButton okButton = new EntityItemButton();
                okButton.Name = "OK";
                okButton.GetInvokeDelegate = new EntityItemButtonCommandDelegate((viewer, entity) =>
                {
                    return new Task(() =>
                    {
                        viewer.Dispatcher.Invoke(() => viewer.DialogResult = true);
                    });
                });
                model.ItemButtons = new IEntityViewButton[] { okButton };

                return model;
            }));
        }
Example #2
0
            public override void Execute(object parameter)
            {
                var viewer = (EntityViewer)ServiceProvider.GetService(typeof(EntityViewer));
                var entity = (IEntity)viewer._ItemsView.SelectedItem;
                EntityItemButton button = (EntityItemButton)parameter;

                button.SetTarget(ServiceProvider, entity);
                button.InvokeDelegate.Start();
            }
Example #3
0
        protected virtual Task <EntityViewModel <TEntity> > GetViewModel(IQueryable <TEntity> queryable, int page, int size)
        {
            return(Task.Run <EntityViewModel <TEntity> >(() =>
            {
                EntityViewModel <TEntity> model = new EntityViewModel <TEntity>(queryable, page, size);
                model.Headers = Metadata.ViewProperties;

                EntityViewButton createButton = new EntityViewButton();
                createButton.Name = "Create";
                createButton.GetInvokeDelegate = new EntityViewButtonCommandDelegate(viewer =>
                {
                    return new Task(async() =>
                    {
                        var item = EntityQueryable.Create();
                        bool?result = null;
                        await viewer.Dispatcher.Invoke(async() =>
                        {
                            viewer.IsLoading = true;
                            var editor = await GetEditor(item);
                            result = editor.ShowDialog();
                        });
                        if (result == true)
                        {
                            await Update(item);
                            model.UpdateTotalPage();
                            model.Items = model.Items.Concat(new TEntity[] { item }).ToArray();
                        }
                        viewer.Dispatcher.Invoke(() =>
                        {
                            viewer.IsLoading = false;
                        });
                    });
                });
                model.ViewButtons = new IViewButton[] { createButton };

                EntityItemButton editButton = new EntityItemButton();
                editButton.Name = "Edit";
                editButton.GetInvokeDelegate = new EntityItemButtonCommandDelegate((viewer, entity) =>
                {
                    return new Task(async() =>
                    {
                        var item = (TEntity)entity;
                        bool?result = null;
                        await viewer.Dispatcher.Invoke(async() =>
                        {
                            viewer.IsLoading = true;
                            var editor = await GetEditor(item);
                            result = editor.ShowDialog();
                        });
                        if (result == true)
                        {
                            await Update(item);
                        }
                        viewer.Dispatcher.Invoke(() =>
                        {
                            viewer.IsLoading = false;
                        });
                    });
                });
                EntityItemButton removeButton = new EntityItemButton();
                removeButton.Name = "Remove";
                removeButton.GetInvokeDelegate = new EntityItemButtonCommandDelegate((viewer, entity) =>
                {
                    return new Task(async() =>
                    {
                        viewer.Dispatcher.Invoke(() =>
                        {
                            viewer.IsLoading = true;
                        });
                        await EntityQueryable.RemoveAsync(entity.Index);
                        model.Items = await EntityQueryable.ToArrayAsync(queryable.Skip(page).Take(size));
                        viewer.Dispatcher.Invoke(() =>
                        {
                            viewer.IsLoading = false;
                        });
                    });
                });
                model.ItemButtons = new IEntityViewButton[] { editButton, removeButton };

                return model;
            }));
        }