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.
Fakes/Server/CslaDataProvider/Customer.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="Customer.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.Linq;
11using System.Text;
12using System.Threading.Tasks;
13using Csla;
14using Csla.Security;
15using Csla.Core;
17
19{
20 public enum CustomeType
21 {
22 Active,
24 }
25
27 public class Customer : BusinessBase<Customer>
28 {
29 const int customerIDThrowsException = 99;
30
31 private Customer() { }
32
33 internal static Customer NewCustomer()
34 {
35 var returnValue = new Customer();
36 returnValue.Name = "New";
37 returnValue.MarkAsChild();
38 return returnValue;
39 }
40
41 private static PropertyInfo<int> IdProperty = RegisterProperty<int>(c=>c.Id, "Customer Id", 0);
42 public int Id
43 {
44 get
45 {
46 return GetProperty<int>(IdProperty);
47 }
48 set
49 {
50 SetProperty<int>(IdProperty, value);
51 }
52 }
53
54 private static PropertyInfo<string> NameProperty = RegisterProperty<string>(c=>c.Name, "Customer Name", "");
55 public string Name
56 {
57 get
58 {
59 return GetProperty<string>(NameProperty);
60 }
61 set
62 {
63 SetProperty<string>(NameProperty, value);
64 }
65 }
66
67 private static PropertyInfo<string> MethodProperty = RegisterProperty<string>(c=>c.Method, "Method", "");
68 public string Method
69 {
70 get
71 {
72 return GetProperty<string>(MethodProperty);
73 }
74 set
75 {
76 SetProperty<string>(MethodProperty, value);
77 }
78 }
79
80
81 private static PropertyInfo<SmartDate> DateCreatedProperty = RegisterProperty<SmartDate>(c=>c.DateCreated, "Date Created On");
82 public string DateCreated
83 {
84 get
85 {
86 return GetProperty<SmartDate>(DateCreatedProperty).Text;
87 }
88 set
89 {
90 SmartDate test = new SmartDate();
91 if (SmartDate.TryParse(value, ref test) == true)
92 {
93 SetProperty<SmartDate>(DateCreatedProperty, test);
94 }
95 }
96 }
97
98
99 private static PropertyInfo<bool> ThrowExceptionProperty = RegisterProperty<bool>(c=>c.ThrowException, "ThrowException", false);
100 public bool ThrowException
101 {
102 get
103 {
104 return GetProperty<bool>(ThrowExceptionProperty);
105 }
106 set
107 {
108 LoadProperty<bool>(ThrowExceptionProperty, value);
109 }
110 }
111
112 private static PropertyInfo<DateTimeOffset> DateTimeOffsetNullProperty = RegisterProperty<DateTimeOffset>(c=>c.DateTimeOffsetNull, "DateTimeOffsetNull");
113 public DateTimeOffset DateTimeOffsetNull
114 {
115 get
116 {
117 return GetProperty(DateTimeOffsetNullProperty);
118 }
119 set
120 {
121 LoadProperty(DateTimeOffsetNullProperty, value);
122 }
123 }
124
125 private static PropertyInfo<DateTimeOffset> DateTimeOffsetNotNullProperty = RegisterProperty<DateTimeOffset>(c=>c.DateTimeOffsetNotNull, "DateTimeOffsetNotNull", DateTimeOffset.Now);
126 public DateTimeOffset DateTimeOffsetNotNull
127 {
128 get
129 {
130 return GetProperty(DateTimeOffsetNotNullProperty);
131 }
132 set
133 {
134 LoadProperty(DateTimeOffsetNotNullProperty, value);
135 }
136 }
137
138 private static PropertyInfo<DateTimeOffset?> DateTimeOffsetNullableProperty = RegisterProperty<DateTimeOffset?>(c=>c.DateTimeOffsetNullable, "DateTimeOffsetNullable");
139 public DateTimeOffset? DateTimeOffsetNullable
140 {
141 get
142 {
143 return GetProperty(DateTimeOffsetNullableProperty);
144 }
145 set
146 {
147 LoadProperty(DateTimeOffsetNullableProperty, value);
148 }
149 }
150
151 private static PropertyInfo<CustomeType> TypeProperty = RegisterProperty(c=>c.Type, "Customer Type", CustomeType.Active);
153 {
154 get
155 {
156 return GetProperty(TypeProperty);
157 }
158 set
159 {
160 SetProperty(TypeProperty, value);
161 }
162 }
163
164
165 private static PropertyInfo<CustomerContactList> ContactsProperty = RegisterProperty<CustomerContactList>(c=>c.Contacts, "Contacts List");
167 {
168 get
169 {
170 return GetProperty<CustomerContactList>(ContactsProperty);
171 }
172 }
173
174 protected override void AddBusinessRules()
175 {
176 BusinessRules.AddRule(new Csla.Rules.CommonRules.MinValue<int>(IdProperty, 1));
177 }
178
179
180 [Serializable()]
181 public class FetchCriteria : CriteriaBase<FetchCriteria>
182 {
183 public FetchCriteria() { }
184
185 public FetchCriteria(int customerID)
186 : base()
187 {
188 _customerId = customerID;
189 }
190
191 private int _customerId;
192
193 public int CustomerID
194 {
195 get
196 {
197 return _customerId;
198 }
199 }
200
201 protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
202 {
203 base.OnGetState(info, mode);
204 info.AddValue("_customerId", _customerId);
205 }
206 protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
207 {
208 base.OnSetState(info, mode);
209 _customerId = info.GetValue<int>("_customerId");
210 }
211 }
212
213 protected void DataPortal_Fetch(int criteria, [Inject] IChildDataPortal<CustomerContactList> childDataPortal)
214 {
215 LoadProperty(IdProperty, criteria);
216 LoadProperty(NameProperty, "Customer Name for Id: " + criteria.ToString());
217 LoadProperty(DateCreatedProperty, new SmartDate(new DateTime(2000 + criteria, 1, 1)));
218 LoadProperty(ContactsProperty, childDataPortal.FetchChild(criteria));
219 LoadProperty(DateTimeOffsetNotNullProperty, DateTimeOffset.Now);
220 LoadProperty(TypeProperty, CustomeType.Inactive);
221
222 if (criteria == customerIDThrowsException)
223 throw new ApplicationException("Test for Silverlight DataSource Error!");
224 }
225
226 protected void DataPortal_Create(int criteria, [Inject] IChildDataPortal<CustomerContactList> childDataPortal)
227 {
228 LoadProperty(IdProperty, criteria);
229 LoadProperty(NameProperty, "New Customer for Id: " + criteria.ToString());
230 LoadProperty(DateCreatedProperty, new SmartDate(DateTime.Today));
231 LoadProperty(DateTimeOffsetNotNullProperty, DateTimeOffset.Now);
232 LoadProperty(ContactsProperty, childDataPortal.FetchChild(0));
233 }
234
235 [DeleteSelf]
236 protected void DataPortal_DeleteSelf()
237 {
238 Method = "Deleted Customer " + GetProperty<string>(NameProperty);
239 }
240
241 [Delete]
242 protected void DataPortal_Delete(int criteria)
243 {
244 Method = "Deleted Customer ID " + criteria.ToString();
245 }
246
247 [Insert]
248 protected void DataPortal_Insert([Inject] IChildDataPortal<CustomerContactList> contactsListDataPortal)
249 {
250 Method = "Inserted Customer " + GetProperty<string>(NameProperty);
251 contactsListDataPortal.UpdateChild(ReadProperty(ContactsProperty));
252 }
253
254 [Update]
255 protected void DataPortal_Update([Inject] IChildDataPortal<CustomerContactList> contactsListDataPortal)
256 {
257 Method = "Updating Customer " + GetProperty<string>(NameProperty);
258 contactsListDataPortal.UpdateChild(ReadProperty(ContactsProperty));
259 }
260 }
261
262
264 public class CustomerWO_DP_XYZ : BusinessBase<CustomerWO_DP_XYZ>
265 {
266 [Create]
267 private async Task Create()
268 {
269 await BusinessRules.CheckRulesAsync();
270 }
271 }
272}
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.
Business rule for a minimum value.
Definition: CommonRules.cs:311
Object containing the serialization data for a specific object.
override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
void DataPortal_Fetch(int criteria, [Inject] IChildDataPortal< CustomerContactList > childDataPortal)
void DataPortal_Insert([Inject] IChildDataPortal< CustomerContactList > contactsListDataPortal)
void DataPortal_Update([Inject] IChildDataPortal< CustomerContactList > contactsListDataPortal)
void DataPortal_Create(int criteria, [Inject] IChildDataPortal< CustomerContactList > childDataPortal)
Task CheckRulesAsync()
Invokes all rules for the business type.
Interface defining the members of the child data portal type.
StateMode
Indicates the reason the MobileFormatter functionality has been invoked.
Definition: StateMode.cs:20
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Delete
Delete operation.
Provides a date data type that understands the concept of an empty date value.
Definition: SmartDate.cs:32
static bool TryParse(string value, ref SmartDate result)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:633