CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
CslaDataProviderCommandManager.cs
Go to the documentation of this file.
1#if !XAMARIN && !WINDOWS_UWP
2//-----------------------------------------------------------------------
3// <copyright file="CslaDataProviderCommandManager.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Implements support for RoutedCommands that can</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.Windows.Input;
11using System.ComponentModel;
12
13namespace Csla.Xaml
14{
24 public class CslaDataProviderCommandManager : System.Windows.UIElement
25 {
26 private CslaDataProvider _provider;
27
28 private CslaDataProvider Provider
29 {
30 get { return _provider; }
31 }
32
34 {
35 _provider = provider;
36 }
37
39 {
40 CommandBinding binding;
41
42 binding = new CommandBinding(ApplicationCommands.Save, SaveCommand, CanExecuteSave);
43 CommandManager.RegisterClassCommandBinding(typeof(CslaDataProviderCommandManager), binding);
44
45 binding = new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecuteUndo);
46 CommandManager.RegisterClassCommandBinding(typeof(CslaDataProviderCommandManager), binding);
47
48 binding = new CommandBinding(ApplicationCommands.New, NewCommand, CanExecuteNew);
49 CommandManager.RegisterClassCommandBinding(typeof(CslaDataProviderCommandManager), binding);
50
51 binding = new CommandBinding(ApplicationCommands.Delete, RemoveCommand, CanExecuteRemove);
52 CommandManager.RegisterClassCommandBinding(typeof(CslaDataProviderCommandManager), binding);
53 }
54
55 private static void CanExecuteSave(object target, CanExecuteRoutedEventArgs e)
56 {
57 bool result = false;
59 if (ctl != null && ctl.Provider != null)
60 {
62 if (ibiz != null)
63 result = ibiz.IsSavable;
64 else
65 {
66 Csla.Core.IEditableCollection icol = ctl.Provider.Data as Csla.Core.IEditableCollection;
67 if (icol != null)
68 result = icol.IsSavable;
69 }
70 }
71 e.CanExecute = result;
72 }
73
74 private static void SaveCommand(object target, ExecutedRoutedEventArgs e)
75 {
77 if (ctl != null && ctl.Provider != null)
78 ctl.Provider.Save();
79 }
80
81 private static void CanExecuteUndo(object target, CanExecuteRoutedEventArgs e)
82 {
83 bool result = false;
85 if (ctl != null && ctl.Provider != null)
86 {
87 if (ctl.Provider.Data != null)
88 {
90 if (ibiz != null)
91 result = ibiz.IsDirty;
92 else
93 {
94 Csla.Core.IEditableCollection icol = ctl.Provider.Data as Csla.Core.IEditableCollection;
95 if (icol != null)
96 result = icol.IsDirty;
97 }
98 }
99 }
100 e.CanExecute = result;
101 }
102
103 private static void UndoCommand(object target, ExecutedRoutedEventArgs e)
104 {
106 if (ctl != null && ctl.Provider != null)
107 ctl.Provider.Cancel();
108 }
109
110 private static void CanExecuteNew(object target, CanExecuteRoutedEventArgs e)
111 {
112 bool result = false;
114 if (ctl != null && ctl.Provider != null)
115 {
116 if (ctl.Provider.Data != null)
117 {
118 IBindingList list = ctl.Provider.Data as IBindingList;
119 if (list != null)
120 {
121 result = list.AllowNew;
122 if (result && !Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, ctl.Provider.Data))
123 result = false;
124 }
125 }
126 }
127 e.CanExecute = result;
128 }
129
130 private static void NewCommand(object target, ExecutedRoutedEventArgs e)
131 {
133 if (ctl != null && ctl.Provider != null)
134 ctl.Provider.AddNew();
135 }
136
137 private static void CanExecuteRemove(object target, CanExecuteRoutedEventArgs e)
138 {
139 bool result = false;
141 if (ctl != null && ctl.Provider != null)
142 {
143 if (ctl.Provider.Data != null)
144 {
145 Csla.Core.BusinessBase bb = e.Parameter as Csla.Core.BusinessBase;
146 IBindingList list;
147 if (bb != null)
148 list = bb.Parent as IBindingList;
149 else
150 list = ctl.Provider.Data as IBindingList;
151 if (list != null)
152 {
153 result = list.AllowRemove;
154 if (result && !Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, ctl.Provider.Data))
155 result = false;
156 }
157 }
158 }
159 e.CanExecute = result;
160 }
161
162 private static void RemoveCommand(object target, ExecutedRoutedEventArgs e)
163 {
165 if (ctl != null && ctl.Provider != null)
166 ctl.Provider.RemoveItem(null, new ExecuteEventArgs { MethodParameter = e.Parameter });
167 }
168 }
169}
170#endif
This is the non-generic base class from which most business objects will be derived.
Core.IParent Parent
Provide access to the parent reference for use in child object code.
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Implements support for RoutedCommands that can be executed by the CslaDataProvider control.
Wraps and creates a CSLA .NET-style object that you can use as a binding source.
object AddNew()
Adds a new item to the object if the object implements IBindingList and AllowNew is true.
void Cancel()
Cancels changes to the business object, returning it to its previous state.
void RemoveItem(object sender, ExecuteEventArgs e)
Removes an item from the list if the object implements IBindingList and AllowRemove is true.
void Save()
Accepts changes to the business object, and commits them by calling the object's Save() method.
Arguments passed to a method invoked by the Execute trigger action.
Defines the common methods required by all editable CSLA single objects.
Defines the common methods required by all editable CSLA collection objects.
bool IsSavable
Returns true if this object is both dirty and valid.
bool IsDirty
Returns true if this object's data, or any of its fields or child objects data, has been changed.
Definition: ITrackStatus.cs:73