9using System.Collections.Generic;
10using System.ComponentModel;
12using System.Linq.Expressions;
13using System.Threading.Tasks;
52 if (oldValue is INotifyPropertyChanged oldObj)
54 if (newValue is INotifyPropertyChanged newObj)
94 Model = await factory();
119 if (
Model is Core.ITrackStatus obj && !obj.IsSavable)
142 if (
Model is Core.ISavable savable)
144 var result = (T)await savable.SaveAsync();
145 if (
Model is Core.IEditableBusinessObject editable)
146 new Core.GraphMerger().MergeGraph(editable, (Core.IEditableBusinessObject)result);
162 if (!ReferenceEquals(_model, value))
170 private readonly Dictionary<string, object> _info =
new Dictionary<string, object>();
181 if (property ==
null)
182 throw new ArgumentNullException(nameof(property));
184 var keyName =
property.GetKey();
185 var identifier = Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create(property);
186 return GetPropertyInfo(keyName, identifier.Model, identifier.FieldName);
199 if (property ==
null)
200 throw new ArgumentNullException(nameof(property));
202 var keyName =
property.GetKey() + $
"[{id}]";
203 var identifier = Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create(property);
204 return GetPropertyInfo(keyName, identifier.Model, identifier.FieldName);
216 var keyName =
Model.GetType().FullName +
"." + propertyName;
230 var keyName =
Model.GetType().FullName +
"." + propertyName + $
"[{id}]";
237 if (_info.TryGetValue(keyName, out
object temp))
244 _info.Add(keyName, result);
262 if (
Model is IDataErrorInfo obj)
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
static bool CanDeleteObject()
Gets a value indicating whether the current user is authorized to delete an instance of the business ...
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
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.
static bool CanGetObject()
Gets a value indicating whether the current user is authorized to retrieve an instance of the busines...
static bool CanEditObject()
Gets a value indicating whether the current user is authorized to edit/save an instance of the busine...
T Model
Gets or sets the Model object.
Action ModelChanged
Event raised when Model has changed
static bool CanCreateObject()
Gets a value indicating whether the current user is authorized to create an instance of the business ...
virtual void OnModelPropertyChanged(string propertyName)
Raises the ModelPropertyChanged event
ViewModel(IDataPortal< T > dataPortal)
Creates an instance of the type
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-...
This is the client-side DataPortal.
Maintains metadata about a property.
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Exposes metastate for a property.
Interface defining the members of the data portal type.
AuthorizationActions
Authorization actions.