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.
EditablePerson.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="EditablePerson.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;
13using System.Diagnostics;
14using System.ComponentModel.DataAnnotations;
15
16namespace Csla.Test.Windows
17{
18#if TESTING
19 [DebuggerNonUserCode]
20#endif
21 [Serializable()]
22 public class EditablePerson : BusinessBase<EditablePerson>
23 {
24 private EditablePerson()
25 {
26 LoadProperty(FirstNameProperty, "John");
27 LoadProperty(LastNameProperty, "Doe");
28 LoadProperty(MiddleNameProperty, "A");
29 LoadProperty(PlaceOfBirthProperty, "New York");
30 }
32 {
33 var tmp = new EditablePerson();
34 tmp.MarkOld();
35 return tmp;
36 }
37
38 public static EditablePerson GetEditablePerson(int authLevel)
39 {
40 var tmp = new EditablePerson();
41 tmp.LoadProperty(AuthLevelProperty, authLevel);
42 tmp.MarkOld();
43 return tmp;
44 }
45
47 {
48 return new EditablePerson();
49 }
50
51 public static readonly PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(c => c.FirstName);
52 [Required()]
53 public string FirstName
54 {
55 get { return GetProperty(FirstNameProperty); }
56 set { SetProperty(FirstNameProperty, value); }
57 }
58
59 public static readonly PropertyInfo<string> LastNameProperty = RegisterProperty<string>(c => c.LastName, "Last name");
60 public string LastName
61 {
62 get { return GetProperty(LastNameProperty); }
63 set { SetProperty(LastNameProperty, value); }
64 }
65
66 public static readonly PropertyInfo<string> MiddleNameProperty = RegisterProperty(new PropertyInfo<string>("MiddleName"));
67 public string MiddleName
68 {
69 get { return GetProperty(MiddleNameProperty); }
70 set { SetProperty(MiddleNameProperty, value); }
71 }
72
73 public static readonly PropertyInfo<string> PlaceOfBirthProperty = RegisterProperty(new PropertyInfo<string>("PlaceOfBirth"));
74 public string PlaceOfBirth
75 {
76 get { return GetProperty(PlaceOfBirthProperty); }
77 set { SetProperty(PlaceOfBirthProperty, value); }
78 }
79
80 public static readonly PropertyInfo<int> AuthLevelProperty = RegisterProperty(new PropertyInfo<int>("AuthLevel"));
81 public int AuthLevel
82 {
83 get { return GetProperty(AuthLevelProperty); }
84 set { SetProperty(AuthLevelProperty, value); }
85 }
86
87 public override bool CanReadProperty(Csla.Core.IPropertyInfo propertyName)
88 {
89 if (propertyName.Name == FirstNameProperty.Name)
90 {
91 return ReadProperty(AuthLevelProperty) > 0;
92 }
93
94 return base.CanReadProperty(propertyName);
95 }
96
97
98 public override bool CanWriteProperty(Csla.Core.IPropertyInfo propertyName)
99 {
100 if (propertyName.Name == FirstNameProperty.Name)
101 {
102 return ReadProperty(AuthLevelProperty) > 1;
103 }
104
105 return base.CanWriteProperty(propertyName);
106 }
107
108 protected override void OnPropertyChanged(Core.IPropertyInfo propertyInfo)
109 {
110 using (BypassPropertyChecks)
111 {
112 if (AuthLevel == 3)
113 {
114 FirstName = "New First Name Value";
115 LastName = "New Last Name Value";
116 MiddleName = "New Middle Name Value";
117 PlaceOfBirth = "New PlaceOfBirth Value";
118 }
119
120 }
121 base.OnPropertyChanged(propertyInfo);
122 }
123
124 [RunLocal()]
125 [Insert]
126 protected void DataPortal_Insert()
127 {
128 DoInsertUpdate();
129 }
130
131 [RunLocal()]
132 [Update]
133 protected void DataPortal_Update()
134 {
135 DoInsertUpdate();
136 }
137
138 private void DoInsertUpdate()
139 {
140 if (this.AuthLevel == 6)
141 {
142 throw new InvalidProgramException();
143 }
144
145 }
146
147 }
148}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
override bool CanWriteProperty(Csla.Core.IPropertyInfo propertyName)
static readonly PropertyInfo< string > FirstNameProperty
static EditablePerson GetEditablePerson(int authLevel)
override bool CanReadProperty(Csla.Core.IPropertyInfo propertyName)
static readonly PropertyInfo< string > LastNameProperty
static readonly PropertyInfo< int > AuthLevelProperty
static EditablePerson NewEditablePerson()
static EditablePerson GetEditablePerson()
static readonly PropertyInfo< string > PlaceOfBirthProperty
override void OnPropertyChanged(Core.IPropertyInfo propertyInfo)
static readonly PropertyInfo< string > MiddleNameProperty
Maintains metadata about a property.
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).