9using System.Collections.Generic;
15using System.Threading.Tasks;
39 public T
Item {
get;
set; }
46 public async Task<bool>
SaveAsync(
bool forceUpdate =
false)
51 AddBrokenRuleInfo(
Item,
null);
52 if (ModelState.IsValid)
54 Item = (T) await
Item.SaveAsync(forceUpdate);
60 AddBrokenRuleInfo(
Item, ex.Message);
64 if (ex.BusinessException !=
null)
65 ModelState.AddModelError(
string.Empty, ex.BusinessException.Message);
67 ModelState.AddModelError(
string.Empty, ex.Message);
71 ModelState.AddModelError(
string.Empty, ex.Message);
76 private void AddBrokenRuleInfo(T item,
string defaultText)
80 var errors = bb.BrokenRulesCollection.
82 foreach (var rule
in errors)
84 if (
string.IsNullOrEmpty(rule.Property))
86 ModelState.AddModelError(
string.Empty, rule.Description);
90 var modelItem = ModelState
91 .Where(r => r.Key == rule.Property || r.Key.EndsWith($
".{rule.Property}")).FirstOrDefault();
92 var key = modelItem.Key ??
string.Empty;
93 ModelState.AddModelError(key, rule.Description);
99 ModelState.AddModelError(
string.Empty, defaultText);
103 private readonly Dictionary<string, PropertyInfo> _info =
new Dictionary<string, PropertyInfo>();
114 if (!_info.TryGetValue(propertyName, out
PropertyInfo info))
117 _info.Add(propertyName, info);
Provides consistent context information between the client and server DataPortal objects.
Exposes metastate for a property.
Custom PageModel for CSLA .NET
bool CanDeleteItem()
Gets a value indicating whether the current user is authorized to delete an instance of the business ...
bool CanGetItem()
Gets a value indicating whether the current user is authorized to retrieve an instance of the busines...
T Item
Gets or sets the business domain model object.
bool CanCreateItem()
Gets a value indicating whether the current user is authorized to create an instance of the business ...
PropertyInfo GetPropertyInfo(string propertyName)
Get a PropertyInfo object for a property of the Model.
async Task< bool > SaveAsync(bool forceUpdate=false)
Save the Item
PageModel(ApplicationContext applicationContext)
Creates an instance of the type.
bool CanEditItem()
Gets a value indicating whether the current user is authorized to edit/save an instance of the busine...
This is the base class from which most business objects will be derived.
virtual bool IsValid
Returns true if the object and its child objects are currently valid, false if the object or any of i...
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Tracks the business rules for a business object.
static bool HasPermission(ApplicationContext applicationContext, AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Exception class indicating that there was a validation problem with a business object.
Specifies that the object can save itself.
AuthorizationActions
Authorization actions.
RuleSeverity
Values for validation rule severities.