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.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
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 Csla;
13using Csla.Security;
14using Csla.Core;
16
18{
20 public class Customer : BusinessBase<Customer>
21 {
22 const int customerIDThrowsException = 99;
23
24 private Customer() { }
25
26 internal static Customer NewCustomer()
27 {
28 var returnValue = new Customer();
29 returnValue.Name = "New";
30 return returnValue;
31 }
32
33 private static PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id, "Customer Id", 0);
34 public int Id
35 {
36 get
37 {
38 return GetProperty<int>(IdProperty);
39 }
40 set
41 {
42 SetProperty<int>(IdProperty, value);
43 }
44 }
45
46 private static PropertyInfo<string> NameProperty = RegisterProperty<string>(c => c.Name, "Customer Name", "");
47 public string Name
48 {
49 get
50 {
51 return GetProperty<string>(NameProperty);
52 }
53 set
54 {
55 SetProperty<string>(NameProperty, value);
56 }
57 }
58
59 private static PropertyInfo<string> MethodProperty = RegisterProperty<string>(c => c.Method, "Method", "");
60 public string Method
61 {
62 get
63 {
64 return GetProperty<string>(MethodProperty);
65 }
66 set
67 {
68 SetProperty<string>(MethodProperty, value);
69 }
70 }
71
72
73 private static PropertyInfo<Csla.SmartDate> DateCreatedProperty = RegisterProperty<Csla.SmartDate>(c => c.DateCreated, "Date Created On");
74 public string DateCreated
75 {
76 get
77 {
78 return GetProperty<Csla.SmartDate>(DateCreatedProperty).Text;
79 }
80 set
81 {
82 Csla.SmartDate test = new Csla.SmartDate();
83 if (Csla.SmartDate.TryParse(value, ref test) == true)
84 {
85 SetProperty<Csla.SmartDate>(DateCreatedProperty, test);
86 }
87 }
88 }
89
90
91 private static PropertyInfo<bool> ThrowExceptionProperty = RegisterProperty<bool>(c => c.ThrowException, "ThrowException", false);
92 public bool ThrowException
93 {
94 get
95 {
96 return GetProperty<bool>(ThrowExceptionProperty);
97 }
98 set
99 {
100 LoadProperty<bool>(ThrowExceptionProperty, value);
101 }
102 }
103
104 protected override void AddBusinessRules()
105 {
106 BusinessRules.AddRule(new Csla.Rules.CommonRules.MinValue<int>(IdProperty, 1));
107 }
108
109
110 [Serializable()]
111 public class FetchCriteria : CriteriaBase<FetchCriteria>
112 {
113 public FetchCriteria() { }
114
115 public FetchCriteria(int customerID)
116 {
117 _customerId = customerID;
118 }
119
120 private int _customerId;
121
122 public int CustomerID
123 {
124 get
125 {
126 return _customerId;
127 }
128 }
129
130 protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
131 {
132 base.OnGetState(info, mode);
133 info.AddValue("_customerId", _customerId);
134 }
135 protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
136 {
137 base.OnSetState(info, mode);
138 _customerId = info.GetValue<int>("_customerId");
139 }
140 }
141
142 internal static Customer GetCustomer(int customerID)
143 {
144 Customer newCustomer = new Customer();
145 newCustomer.DataPortal_Fetch(customerID);
146 newCustomer.MarkOld();
147 return newCustomer;
148 }
149
150 protected void DataPortal_Fetch(int criteria)
151 {
152 LoadProperty(IdProperty, criteria);
153 LoadProperty(NameProperty, "Customer Name for Id: " + criteria.ToString());
154 LoadProperty(DateCreatedProperty, new Csla.SmartDate(new DateTime(2000 + criteria, 1, 1)));
155
156 if (criteria == customerIDThrowsException)
157 throw new ApplicationException("Test Error!");
158 }
159
160 protected void DataPortal_Create(int criteria)
161 {
162 LoadProperty(IdProperty, criteria);
163 LoadProperty(NameProperty, "New Customer for Id: " + criteria.ToString());
164 LoadProperty(DateCreatedProperty, new Csla.SmartDate(DateTime.Today));
165 }
166
167 [DeleteSelf]
168 protected void DataPortal_DeleteSelf()
169 {
170 Method = "Deleted Customer " + GetProperty<string>(NameProperty);
171 }
172
173 [Delete]
174 protected void DataPortal_Delete(int criteria)
175 {
176 Method = "Deleted Customer ID " + criteria.ToString();
177 }
178
179 [Insert]
180 protected void DataPortal_Insert()
181 {
182 Method = "Inserted Customer " + GetProperty<string>(NameProperty);
183 }
184
185 [Update]
186 protected void DataPortal_Update()
187 {
188 Method = "Updating Customer " + GetProperty<string>(NameProperty);
189 }
190
191 }
192
193
194
195
196}
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)
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