CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
RollBack/RollbackRoot.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="RollbackRoot.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11
13{
14 [Serializable()]
15 public class RollbackRoot : BusinessBase<RollbackRoot>
16 {
17 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(nameof(Data));
18 public static PropertyInfo<bool> FailProperty = RegisterProperty<bool>(nameof(Fail));
19
20 protected override object GetIdValue()
21 {
22 return GetProperty(DataProperty);
23 }
24
25 public string Data
26 {
27 get { return GetProperty(DataProperty); }
28 set { SetProperty(DataProperty, value); }
29 }
30
31 public bool Fail
32 {
33 get { return GetProperty(FailProperty); }
34 set { SetProperty(FailProperty, value); }
35 }
36
37 [Serializable()]
38 protected class Criteria : CriteriaBase<Criteria>
39 {
40 private static PropertyInfo<string> DataProperty = RegisterProperty<string>(nameof(Data));
41
42 public Criteria()
43 {
44 Data = "<new>";
45 }
46
47 public Criteria(string data)
48 {
49 this.Data = data;
50 }
51
52 public string Data
53 {
54 get { return ReadProperty(DataProperty); }
55 set { LoadProperty(DataProperty, value); }
56 }
57 }
58
60 {
61 return dataPortal.Create(new Criteria());
62 }
63
64 public static RollbackRoot GetRoot(string data, IDataPortal<RollbackRoot> dataPortal)
65 {
66 return dataPortal.Fetch(new Criteria(data));
67 }
68
69 public static void DeleteRoot(string data, IDataPortal<RollbackRoot> dataPortal)
70 {
71 dataPortal.Delete(new Criteria(data));
72 }
73
74 private void DataPortal_Create(Criteria criteria)
75 {
76 Data = criteria.Data;
77 TestResults.AddOrOverwrite("Root", "Created");
78 }
79
80 protected void DataPortal_Fetch(Criteria criteria)
81 {
82 Data = criteria.Data;
83 MarkOld();
84 TestResults.AddOrOverwrite("Root", "Fetched");
85 }
86
87 [Insert]
88 protected void DataPortal_Insert()
89 {
90 TestResults.AddOrOverwrite("Root", "Inserted");
91 }
92
93 [Update]
94 protected void DataPortal_Update()
95 {
96 //we would update here
97 TestResults.AddOrOverwrite("Root", "Updated");
98
99 if (Fail)
100 throw new Exception("fail Update");
101 }
102
103 [DeleteSelf]
104 protected void DataPortal_DeleteSelf()
105 {
106 TestResults.AddOrOverwrite("Root", "Deleted self");
107 }
108
109 [Delete]
110 protected void DataPortal_Delete(object criteria)
111 {
112 //we would delete here
113 TestResults.AddOrOverwrite("Root", "Deleted");
114 }
115
116 protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
117 {
118 base.OnDeserialized(context);
119 TestResults.AddOrOverwrite("Deserialized", "root Deserialized");
120 }
121 }
122}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Base type from which Criteria classes can be derived in a business class.
Definition: CriteriaBase.cs:25
Maintains metadata about a property.
static PropertyInfo< string > DataProperty
static void DeleteRoot(string data, IDataPortal< RollbackRoot > dataPortal)
override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
static RollbackRoot NewRoot(IDataPortal< RollbackRoot > dataPortal)
void DataPortal_Fetch(Criteria criteria)
static RollbackRoot GetRoot(string data, IDataPortal< RollbackRoot > dataPortal)
static PropertyInfo< bool > FailProperty
override object GetIdValue()
Override this method to return a unique identifying value for this object.
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void AddOrOverwrite(string key, string value)
Overwrite an item in the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:39
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
void Delete(params object[] criteria)
Called by a Shared (static in C#) method in the business class to cause immediate deletion of a speci...
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Delete
Delete operation.