CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
AsyncController.cs
Go to the documentation of this file.
1#if MVC5
2//-----------------------------------------------------------------------
3// <copyright file="Controller.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Provides methods that respond to HTTP requests</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.Threading.Tasks;
11using System.Web.Mvc;
12
13namespace Csla.Web.Mvc
14{
19 public class AsyncController : System.Web.Mvc.AsyncController
20 {
30 protected async Task<bool> SaveObjectAsync<T>(T item, bool forceUpdate) where T : class, Csla.Core.ISavable
31 {
32 return await SaveObjectAsync(item,
33 null,
34 forceUpdate);
35 }
36
47 protected virtual async Task<bool> SaveObjectAsync<T>(T item, Action<T> updateModel, bool forceUpdate) where T : class, Csla.Core.ISavable
48 {
49 try
50 {
51 ViewData.Model = item;
52 if (updateModel != null)
53 updateModel(item);
54 ViewData.Model = await item.SaveAsync(forceUpdate);
55 return true;
56 }
57 catch (Csla.DataPortalException ex)
58 {
59 if (ex.BusinessException != null)
60 ModelState.AddModelError("", ex.BusinessException.Message);
61 else
62 ModelState.AddModelError("", ex.Message);
63 return false;
64 }
65 catch (Exception ex)
66 {
67 ModelState.AddModelError("", ex.Message);
68 return false;
69 }
70 }
71
93 protected void LoadProperty<P>(object obj, PropertyInfo<P> propertyInfo, P newValue)
94 {
95 new ObjectManager().LoadProperty(obj, propertyInfo, newValue);
96 }
97
98 private class ObjectManager : Csla.Server.ObjectFactory
99 {
100 public new void LoadProperty<P>(object obj, PropertyInfo<P> propertyInfo, P newValue)
101 {
102 base.LoadProperty(obj, propertyInfo, newValue);
103 }
104 }
105 }
106}
107#endif
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Specifies that the object can save itself.
Definition: ISavableT.cs:19