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.
Csla.Web.Mvc.Shared/ViewModelBase.cs
Go to the documentation of this file.
1#if !NETSTANDARD2_0 && !NETCORE3_1 && !NET5_0
2//-----------------------------------------------------------------------
3// <copyright file="ViewModelBase.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Base class used to create ViewModel objects that contain the Model object and related elements.</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.Collections.Generic;
11using System.Linq;
12using System.Text;
13using System.Web.Mvc;
14
15namespace Csla.Web.Mvc
16{
22 public abstract class ViewModelBase<T> : IViewModel where T : class
23 {
25 {
26 get { return ModelObject; }
27 set { ModelObject = (T)value; }
28 }
29
33 public T ModelObject { get; set; }
34
44 public virtual bool Save(ModelStateDictionary modelState, bool forceUpdate)
45 {
46 try
47 {
48 var savable = ModelObject as Csla.Core.ISavable;
49 if (savable == null)
50 throw new InvalidOperationException("Save");
51
52 ModelObject = (T)savable.Save(forceUpdate);
53 return true;
54 }
55 catch (Csla.DataPortalException ex)
56 {
57 if (ex.BusinessException != null)
58 modelState.AddModelError("", ex.BusinessException.Message);
59 else
60 modelState.AddModelError("", ex.Message);
61 return false;
62 }
63 catch (Exception ex)
64 {
65 modelState.AddModelError("", ex.Message);
66 return false;
67 }
68 }
69 }
70}
71#endif
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Base class used to create ViewModel objects that contain the Model object and related elements.
virtual bool Save(ModelStateDictionary modelState, bool forceUpdate)
Saves the current Model object if the object implements Csla.Core.ISavable.
Specifies that the object can save itself.
Definition: ISavableT.cs:19
Defines a CSLA .NET MVC viewmodel object.
object ModelObject
Object property for the contained business object