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.
Csla.test/DataPortal/ParentEntity.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ParentEntity.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>DO NOT USE in UI - use the factory method instead</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using System.Data;
12using System.Data.SqlClient;
13
15{
16 [Serializable()]
17 public class ParentEntity : BusinessBase<ParentEntity>
18 {
19 #region "Business methods"
20
21 [NotUndoable()]
22 private string _notUndoable;
23
24 public string NotUndoable
25 {
26 get { return _notUndoable; }
27 set { _notUndoable = value; }
28 }
29
30 public static PropertyInfo<int> IDProperty = RegisterProperty<int>(c => c.ID);
31 public int ID
32 {
33 get { return GetProperty(IDProperty); }
34 private set { LoadProperty(IDProperty, value); }
35 }
36
37 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
38 public string Data
39 {
40 get { return GetProperty(DataProperty); }
41 set { SetProperty(DataProperty, value); }
42 }
43
44 public static PropertyInfo<ChildEntityList> ChildrenProperty = RegisterProperty<ChildEntityList>(p => p.Children);
46 {
47 get { return GetProperty(ChildrenProperty); }
48 }
49
50 public override bool IsDirty
51 {
52 get
53 {
54 return base.IsDirty || Children.IsDirty;
55 }
56 }
57
58 #endregion
59
60 protected override void AddBusinessRules()
61 {
62 //don't need rules for databinding tests
63 //ValidationRules.AddRule(Validation.CommonRules.StringRequired, "Data");
64 }
65
66 #region "constructors"
67
74 public ParentEntity()
75 {
76 //if we need authorization rules:
77 //this.AuthorizationRules.AllowWrite("Data", "Admin");
78 //this.AuthorizationRules.AllowRead("Data", "Admin");
79 }
80
81 #endregion
82
83 #region "Factory Methods"
84
86 {
87 return dataPortal.Create();
88 }
89
91 {
92 return dataPortal.Fetch(new Criteria(ID));
93 }
94
95 public static void DeleteParentEntity(int ID, IDataPortal<ParentEntity> dataPortal)
96 {
97 dataPortal.Delete(new Criteria(ID));
98 }
99
100 #endregion
101
102 #region "Criteria"
103
104 [Serializable()]
105 private class Criteria
106 {
107 public int _id;
108
109 public Criteria(int id)
110 {
111 this._id = id;
112 }
113 }
114
115 #endregion
116
117 #region "Data Access"
118
119 [Create]
120 protected void DataPortal_Create([Inject] IChildDataPortal<ChildEntityList> childDataPortal)
121 {
122 SetProperty(ChildrenProperty, childDataPortal.CreateChild());
124 TestResults.Add("ParentEntity", "Created");
125 BusinessRules.CheckRules();
126 Console.WriteLine("DataPortal_Create");
127 }
128
129 [Fetch]
130 protected void DataPortal_Fetch(object criteria, [Inject] IChildDataPortal<ChildEntityList> childDataPortal)
131 {
132 SetProperty(ChildrenProperty, childDataPortal.CreateChild());
133 Console.WriteLine("DataPortal_Fetch");
135 TestResults.Add("ParentEntity", "Fetched");
136 BusinessRules.CheckRules();
137 }
138
139 [Insert]
140 protected void DataPortal_Insert()
141 {
143 TestResults.Add("ParentEntity", "Inserted");
144 Console.WriteLine("DataPortal_Insert");
145 }
146
147 [Update]
148 protected void DataPortal_Update()
149 {
150 Console.WriteLine("DataPortal_Update");
152 TestResults.Add("ParentEntity", "Updated");
153 }
154
155 [DeleteSelf]
156 protected void DataPortal_DeleteSelf()
157 {
158 Console.WriteLine("DataPortal_DeleteSelf");
160 TestResults.Add("ParentEntity", "Deleted Self");
161 }
162
163 [Delete]
164 protected void DataPortal_Delete(object criteria)
165 {
166 Console.WriteLine("DataPortal_Delete");
168 TestResults.Add("ParentEntity", "Deleted");
169 }
170
171 #endregion
172 }
173}
bool IsDirty
Gets a value indicating whether this object's data has been changed.
Maintains metadata about a property.
static ParentEntity NewParentEntity(IDataPortal< ParentEntity > dataPortal)
void DataPortal_Fetch(object criteria, [Inject] IChildDataPortal< ChildEntityList > childDataPortal)
static ParentEntity GetParentEntity(int ID, IDataPortal< ParentEntity > dataPortal)
void DataPortal_Create([Inject] IChildDataPortal< ChildEntityList > childDataPortal)
ParentEntity()
DO NOT USE in UI - use the factory method instead
static PropertyInfo< ChildEntityList > ChildrenProperty
static void DeleteParentEntity(int ID, IDataPortal< ParentEntity > dataPortal)
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
Definition: TestResults.cs:69
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:29
Interface defining the members of the child data portal type.
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).
@ Fetch
Fetch operation.
@ Create
Create operation.
@ Delete
Delete operation.