10using System.Collections.Generic;
11using Microsoft.AspNetCore.Mvc;
12using Microsoft.AspNetCore.Mvc.RazorPages;
16using System.Threading.Tasks;
30 public T
Item {
get;
set; }
37 public async Task<bool>
SaveAsync(
bool forceUpdate =
false)
42 AddBrokenRuleInfo(
Item,
null);
43 if (ModelState.IsValid)
45 Item = (T) await
Item.SaveAsync(forceUpdate);
51 AddBrokenRuleInfo(
Item, ex.Message);
55 if (ex.BusinessException !=
null)
56 ModelState.AddModelError(
string.Empty, ex.BusinessException.Message);
58 ModelState.AddModelError(
string.Empty, ex.Message);
62 ModelState.AddModelError(
string.Empty, ex.Message);
67 private void AddBrokenRuleInfo(T item,
string defaultText)
71 var errors = bb.BrokenRulesCollection.
73 foreach (var rule
in errors)
75 if (
string.IsNullOrEmpty(rule.Property))
77 ModelState.AddModelError(
string.Empty, rule.Description);
81 var modelItem = ModelState.Where(r => r.Key == rule.Property || r.Key.EndsWith($
".{rule.Property}")).FirstOrDefault();
82 ModelState.AddModelError(modelItem.Key, rule.Description);
88 ModelState.AddModelError(
string.Empty, defaultText);
92 private readonly Dictionary<string, PropertyInfo> _info =
new Dictionary<string, PropertyInfo>();
103 if (!_info.TryGetValue(propertyName, out
PropertyInfo info))
106 _info.Add(propertyName, info);
Exposes metastate for a property.
Custom PageModel for CSLA .NET
static bool CanDeleteItem()
Gets a value indicating whether the current user is authorized to delete an instance of the business ...
static bool CanEditItem()
Gets a value indicating whether the current user is authorized to edit/save an instance of the busine...
T Item
Gets or sets the business domain model object.
PropertyInfo GetPropertyInfo(string propertyName)
Get a PropertyInfo object for a property of the Model.
static bool CanCreateItem()
Gets a value indicating whether the current user is authorized to create an instance of the business ...
async Task< bool > SaveAsync(bool forceUpdate=false)
Save the Item
static bool CanGetItem()
Gets a value indicating whether the current user is authorized to retrieve an instance of the busines...
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(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.