9using System.Collections.Generic;
12#if NETSTANDARD2_0 || NET5_0 || NETCORE3_1
13using System.Threading.Tasks;
16using Microsoft.AspNetCore.Mvc;
27#if NETSTANDARD2_0 || NET5_0 || NETCORE3_1
28 public class Controller : Microsoft.AspNetCore.Mvc.Controller
33#if NETSTANDARD2_0 || NET5_0 || NETCORE3_1
43 protected async Task<bool> SaveObjectAsync<T>(T item,
bool forceUpdate)
44 where T :
class, Core.ISavable
46 return await SaveObjectAsync(item,
null, forceUpdate);
59 protected virtual async Task<bool> SaveObjectAsync<T>(T item, Action<T> updateModel,
bool forceUpdate)
60 where T :
class, Core.ISavable
64 ViewData.Model = item;
65 updateModel?.Invoke(item);
68 AddBrokenRuleInfo(item,
null);
71 ViewData.Model = await item.SaveAsync(forceUpdate);
74 catch (ValidationException ex)
76 AddBrokenRuleInfo(item, ex.Message);
81 if (ex.BusinessException !=
null)
82 ModelState.AddModelError(
string.Empty, ex.BusinessException.Message);
84 ModelState.AddModelError(
string.Empty, ex.Message);
89 ModelState.AddModelError(
string.Empty, ex.Message);
94 private void AddBrokenRuleInfo<T>(T item,
string defaultText) where T :
class, ISavable
98 var errors = bb.BrokenRulesCollection.
100 foreach (var rule
in errors)
102 if (
string.IsNullOrEmpty(rule.Property))
103 ModelState.AddModelError(
string.Empty, rule.Description);
105 ModelState.AddModelError(rule.Property, rule.Description);
110 ModelState.AddModelError(
string.Empty, defaultText);
124 where T :
class, Core.ISavable
126 return SaveObject(item,
141 protected virtual bool SaveObject<T>(T item, Action<T> updateModel,
bool forceUpdate)
142 where T :
class, Core.ISavable
146 ViewData.Model = item;
147 updateModel?.Invoke(item);
149 ViewData.Model = item.SaveAsync(forceUpdate).Result;
151 ViewData.Model = item.Save(forceUpdate);
160 ModelState.AddModelError(
string.Empty, ex.Message);
165 ModelState.AddModelError(
string.Empty, ex.Message);
194 new ObjectManager().LoadProperty(obj, propertyInfo, newValue);
197 private class ObjectManager : Server.ObjectFactory
201 base.LoadProperty(obj, propertyInfo, newValue);
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.
Exception BusinessException
Gets the original server-side exception.
Maintains metadata about a property.
Provides methods that respond to HTTP requests in an ASP.NET MVC web site.
bool SaveObject< T >(T item, bool forceUpdate)
Performs a Save() operation on an editable business object, with appropriate validation and exception...
void LoadProperty< P >(object obj, PropertyInfo< P > propertyInfo, P newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
RuleSeverity
Values for validation rule severities.