9using System.Collections.Generic;
10using System.ComponentModel;
11using System.Linq.Expressions;
12using System.Threading.Tasks;
63 if (oldValue is INotifyPropertyChanged oldObj)
65 if (newValue is INotifyPropertyChanged newObj)
97 Model = await factory();
122 if (
Model is Core.ITrackStatus obj && !obj.IsSavable)
150 if (
Model is Core.ISavable savable)
152 var result = (T)await savable.SaveAsync();
153 if (
Model is Core.IEditableBusinessObject editable)
154 new Core.GraphMerger(
ApplicationContext).MergeGraph(editable, (Core.IEditableBusinessObject)result);
170 if (!ReferenceEquals(_model, value))
179 private readonly Dictionary<string, object> _info =
new Dictionary<string, object>();
190 if (property ==
null)
191 throw new ArgumentNullException(nameof(property));
193 var keyName =
property.GetKey();
194 var identifier =
Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create(property);
195 return GetPropertyInfo(keyName, identifier.Model, identifier.FieldName);
208 if (property ==
null)
209 throw new ArgumentNullException(nameof(property));
211 var keyName =
property.GetKey() + $
"[{id}]";
212 var identifier =
Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create(property);
213 return GetPropertyInfo(keyName, identifier.Model, identifier.FieldName);
225 var keyName =
Model.GetType().FullName +
"." + propertyName;
239 var keyName =
Model.GetType().FullName +
"." + propertyName + $
"[{id}]";
246 if (_info.TryGetValue(keyName, out
object temp))
253 _info.Add(keyName, result);
271 if (
Model is IDataErrorInfo obj)
Provides consistent context information between the client and server DataPortal objects.
Exposes metastate for a property.
Base type for creating your own viewmodel.
Action< T, T > ModelChanging
Event raised when Model is changing
async Task SaveAsync()
Saves the Model
async Task< T > RefreshAsync(Func< Task< T > > factory)
Refresh the Model
string ViewModelErrorText
Gets any error text generated by refresh or save operations
virtual string ModelErrorText
Gets the first validation error message from the Model
PropertyChangedEventHandler ModelPropertyChanged
Event raised when the Model object raises its PropertyChanged event
bool CanEditObject()
Gets a value indicating whether the current user is authorized to edit/save an instance of the busine...
virtual void OnModelChanged()
Raises the ModelChanged event
virtual async Task< T > DoSaveAsync()
Override to provide custom Model save behavior
IPropertyInfo GetPropertyInfo< P >(Expression< Func< P > > property)
Get a PropertyInfo object for a property.
Exception Exception
Gets the last exception caught by the viewmodel during refresh or save operations.
virtual void OnModelChanging(T oldValue, T newValue)
Raises the ModelChanging event
IPropertyInfo GetPropertyInfo(string propertyName)
Get a PropertyInfo object for a property of the Model.
ViewModel(ApplicationContext applicationContext)
Creates an instance of the type.
T Model
Gets or sets the Model object.
bool CanGetObject()
Gets a value indicating whether the current user is authorized to retrieve an instance of the busines...
Action ModelChanged
Event raised when Model has changed
virtual void OnModelPropertyChanged(string propertyName)
Raises the ModelPropertyChanged event
bool CanCreateObject()
Gets a value indicating whether the current user is authorized to create an instance of the business ...
bool CanDeleteObject()
Gets a value indicating whether the current user is authorized to delete an instance of the business ...
Action Saved
Event raised after Model has been saved
IPropertyInfo GetPropertyInfo(string propertyName, string id)
Get a PropertyInfo object for a property of the Model.
This exception is returned for any errors occurring during the server-side DataPortal invocation.
string BusinessExceptionMessage
Gets the Message property from the BusinessException, falling back to the Message value from the top-...
Maintains metadata about a property.
Tracks the business rules for a business object.
static bool HasPermission(ApplicationContext applicationContext, AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Exposes metastate for a property.
AuthorizationActions
Authorization actions.