Free cookie consent management tool by TermsFeed Policy Generator

source: branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs @ 4726

Last change on this file since 4726 was 4647, checked in by mjesner, 14 years ago

#1196

File size: 10.3 KB
Line 
1using HeuristicLab.Services.Authentication.DataAccess;
2using HeuristicLab.Services.Authentication.DataTransfer;
3
4namespace HeuristicLab.Services.Authentication
5{
6    public class Convert
7    {
8
9        #region User
10
11        /// <summary>
12        /// converts data transfer object to data access objet
13        /// </summary>
14        /// <param name="source">data transfer object</param>
15        /// <returns>data access object</returns>
16        public static aspnet_User ToEntity(User source)
17        {
18            if (source == null) return null;
19            return new aspnet_User()
20            {
21                ApplicationId = source.ApplicationId,
22                UserId = source.UserId,
23                UserName = source.UserName,
24                LoweredUserName = source.LoweredUserName,
25                IsAnonymous = source.IsAnonymous,
26                LastActivityDate = source.LastActivityDate
27            };
28        }
29
30        /// <summary>
31        /// converts data access object to data transfer object
32        /// </summary>
33        /// <param name="source">data access object</param>
34        /// <returns>data transfer object</returns>
35        public static User ToDataTransfer(aspnet_User source)
36        {
37            if (source == null) return null;
38            return new User()
39            {
40                ApplicationId = source.ApplicationId,
41                UserId = source.UserId,
42                UserName = source.UserName,
43                LoweredUserName = source.LoweredUserName,
44                IsAnonymous = source.IsAnonymous,
45                LastActivityDate = source.LastActivityDate
46            };
47        }
48
49        /// <summary>
50        /// converts data transfer object to data access object
51        /// </summary>
52        /// <param name="source">data transfer object</param>
53        /// <param name="target">data access object</param>
54        public static void ToEntity(User source, aspnet_User target)
55        {
56            if ((source != null) && (target != null))
57            {
58                target.ApplicationId = source.ApplicationId;
59                target.UserId = source.UserId;
60                target.UserName = source.UserName;
61                target.LoweredUserName = source.LoweredUserName;
62                target.IsAnonymous = source.IsAnonymous;
63                target.LastActivityDate = source.LastActivityDate;
64            }
65
66        }
67
68
69        #endregion
70
71        #region Application
72
73        /// <summary>
74        /// converts data transfer object to data access objet
75        /// </summary>
76        /// <param name="source">data transfer object</param>
77        /// <returns>data access object</returns>
78        public static aspnet_Application ToEntity(Application source)
79        {
80            if (source == null) return null;
81            return new aspnet_Application()
82            {
83                ApplicationId = source.ApplicationId,
84                ApplicationName = source.ApplicationName,
85                LoweredApplicationName = source.LoweredApplicationName,
86                Description = source.Description
87            };
88        }
89
90        /// <summary>
91        /// converts data access object to data transfer object
92        /// </summary>
93        /// <param name="source">data access object</param>
94        /// <returns>data transfer object</returns>
95        public static Application ToDataTransfer(aspnet_Application source)
96        {
97            if (source == null) return null;
98            return new Application()
99            {
100                ApplicationId = source.ApplicationId,
101                ApplicationName = source.ApplicationName,
102                LoweredApplicationName = source.LoweredApplicationName,
103                Description = source.Description
104            };
105        }
106
107        /// <summary>
108        /// converts data transfer object to data access object
109        /// </summary>
110        /// <param name="source">data transfer object</param>
111        /// <param name="target">data access object</param>
112        public static void ToEntity(Application source, aspnet_Application target)
113        {
114            if ((source != null) && (target != null))
115            {
116                target.ApplicationId = source.ApplicationId;
117                target.ApplicationName = source.ApplicationName;
118                target.LoweredApplicationName = source.LoweredApplicationName;
119                target.Description = source.Description;
120            }
121
122        }
123
124        #endregion
125
126        #region Membership
127
128        /// <summary>
129        /// converts data transfer object to data access objet
130        /// </summary>
131        /// <param name="source">data transfer object</param>
132        /// <returns>data access object</returns>
133        public static aspnet_Membership ToEntity(Membership source)
134        {
135            if (source == null) return null;
136            return new aspnet_Membership()
137            {
138                ApplicationId = source.ApplicationId,
139                UserId = source.UserId,
140                Password = source.Password,
141                PasswordAnswer = source.PasswordAnswer,
142                PasswordSalt = source.PasswordSalt,
143                PasswordQuestion = source.PasswordQuestion,
144               
145                Email = source.Email,
146                LoweredEmail = source.LoweredEmail,
147                IsApproved = source.IsApproved,
148                IsLockedOut = source.IsLockedOut,
149                CreateDate = source.CreateDate,
150                LastLoginDate = source.LastLoginDate,
151                LastPasswordChangedDate = source.LastPasswordChangedDate,
152                LastLockoutDate = source.LastLockoutDate,
153                Comment = source.Comment
154
155               
156            };
157        }
158
159        /// <summary>
160        /// converts data access object to data transfer object
161        /// </summary>
162        /// <param name="source">data access object</param>
163        /// <returns>data transfer object</returns>
164        public static Membership ToDataTransfer(aspnet_Membership source)
165        {
166            if (source == null) return null;
167            return new Membership()
168            {
169                ApplicationId = source.ApplicationId,
170                UserId = source.UserId,
171                Password = source.Password,
172                PasswordAnswer = source.PasswordAnswer,
173                PasswordSalt = source.PasswordSalt,
174                PasswordQuestion = source.PasswordQuestion,
175               
176                Email = source.Email,
177                LoweredEmail = source.LoweredEmail,
178                IsApproved = source.IsApproved,
179                IsLockedOut = source.IsLockedOut,
180                CreateDate = source.CreateDate,
181                LastLoginDate = source.LastLoginDate,
182                LastPasswordChangedDate = source.LastPasswordChangedDate,
183                LastLockoutDate = source.LastLockoutDate,
184                Comment = source.Comment
185            };
186        }
187
188        /// <summary>
189        /// converts data transfer object to data access object
190        /// </summary>
191        /// <param name="source">data transfer object</param>
192        /// <param name="target">data access object</param>
193        public static void ToEntity(Membership source, aspnet_Membership target)
194        {
195            if ((source != null) && (target != null))
196            {
197                target.ApplicationId = source.ApplicationId;
198                target.UserId = source.UserId;
199                target.Password = source.Password;
200                target.PasswordAnswer = source.PasswordAnswer;
201                target.PasswordSalt = source.PasswordSalt;
202                target.PasswordQuestion = source.PasswordQuestion;
203               
204                target.Email = source.Email;
205                target.LoweredEmail = source.LoweredEmail;
206                target.IsApproved = source.IsApproved;
207                target.IsLockedOut = source.IsLockedOut;
208                target.CreateDate = source.CreateDate;
209                target.LastLoginDate = source.LastLoginDate;
210                target.LastPasswordChangedDate = source.LastPasswordChangedDate;
211                target.LastLockoutDate = source.LastLockoutDate;
212                target.Comment = source.Comment;
213            }
214
215        }
216
217        #endregion
218
219        #region Role
220
221        /// <summary>
222        /// converts data transfer object to data access objet
223        /// </summary>
224        /// <param name="source">data transfer object</param>
225        /// <returns>data access object</returns>
226        public static aspnet_Role ToEntity(Role source)
227        {
228            if (source == null) return null;
229            return new aspnet_Role()
230            {
231                ApplicationId = source.ApplicationId,
232                RoleId = source.RoleId,
233                RoleName = source.RoleName,
234                LoweredRoleName = source.LoweredRoleName,
235                Description = source.Description
236            };
237        }
238
239        /// <summary>
240        /// converts data access object to data transfer object
241        /// </summary>
242        /// <param name="source">data access object</param>
243        /// <returns>data transfer object</returns>
244        public static Role ToDataTransfer(aspnet_Role source)
245        {
246            if (source == null) return null;
247            return new Role()
248            {
249                ApplicationId = source.ApplicationId,
250                RoleId = source.RoleId,
251                RoleName = source.RoleName,
252                LoweredRoleName = source.LoweredRoleName,
253                Description = source.Description
254            };
255        }
256
257        /// <summary>
258        /// converts data transfer object to data access object
259        /// </summary>
260        /// <param name="source">data transfer object</param>
261        /// <param name="target">data access object</param>
262        public static void ToEntity(Role source, aspnet_Role target)
263        {
264            if ((source != null) && (target != null))
265            {
266                target.ApplicationId = source.ApplicationId;
267                target.RoleId = source.RoleId;
268                target.RoleName = source.RoleName;
269                target.LoweredRoleName = source.LoweredRoleName;
270                target.Description = source.Description;
271            }
272
273        }
274
275        #endregion
276
277    }
278}
Note: See TracBrowser for help on using the repository browser.