9using System.Collections.Generic;
12#if NETSTANDARD2_0 || NET5_0_OR_GREATER || NETCOREAPP3_1
13using System.Threading.Tasks;
27#if NETSTANDARD2_0 || NET5_0_OR_GREATER || NETCOREAPP3_1
28 public class Controller :
Microsoft.AspNetCore.Mvc.Controller
47#if NETSTANDARD2_0 || NET5_0_OR_GREATER || NETCOREAPP3_1
57 protected async Task<bool> SaveObjectAsync<T>(T item,
bool forceUpdate)
58 where T :
class, Core.ISavable
60 return await SaveObjectAsync(item,
null, forceUpdate);
73 protected virtual async Task<bool> SaveObjectAsync<T>(T item, Action<T> updateModel,
bool forceUpdate)
74 where T :
class, Core.ISavable
78 ViewData.Model = item;
79 updateModel?.Invoke(item);
82 AddBrokenRuleInfo(item,
null);
85 ViewData.Model = await item.SaveAsync(forceUpdate);
88 catch (ValidationException ex)
90 AddBrokenRuleInfo(item, ex.Message);
93 catch (DataPortalException ex)
95 if (ex.BusinessException !=
null)
96 ModelState.AddModelError(
string.Empty, ex.BusinessException.Message);
98 ModelState.AddModelError(
string.Empty, ex.Message);
103 ModelState.AddModelError(
string.Empty, ex.Message);
108 private void AddBrokenRuleInfo<T>(T item,
string defaultText) where T :
class, ISavable
110 if (item is BusinessBase bb)
112 var errors = bb.BrokenRulesCollection.
114 foreach (var rule
in errors)
116 if (
string.IsNullOrEmpty(rule.Property))
117 ModelState.AddModelError(
string.Empty, rule.Description);
119 ModelState.AddModelError(rule.Property, rule.Description);
124 ModelState.AddModelError(
string.Empty, defaultText);
138 where T :
class, Core.ISavable
140 return SaveObject(item,
155 protected virtual bool SaveObject<T>(T item, Action<T> updateModel,
bool forceUpdate)
156 where T :
class, Core.ISavable
160 ViewData.Model = item;
161 updateModel?.Invoke(item);
163 ViewData.Model = item.SaveAsync(forceUpdate).Result;
165 ViewData.Model = item.Save(forceUpdate);
174 ModelState.AddModelError(
string.Empty, ex.Message);
179 ModelState.AddModelError(
string.Empty, ex.Message);
211 private class ObjectManager : Server.ObjectFactory
214 : base(applicationContext) { }
218 base.LoadProperty(obj, propertyInfo, newValue);
Provides consistent context information between the client and server DataPortal objects.
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.
Controller(ApplicationContext applicationContext)
Creates a new instance of the type.
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.