Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4885 was 4740, checked in by jwolfing, 14 years ago

#1196 Changed DataTransfer Structure factoring in abstract class. Added new TestClient2 only to test the new method. All other comment lines, are lines they should be changed to the new structure.

File size: 13.9 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.Id,
23                UserName = source.Name,
24                //LoweredUserName = source.LoweredUserName,
25                //IsAnonymous = source.IsAnonymous,
26                LastActivityDate = source.LastActivityDate
27            };
28        }
29
30        ///// <summary>
31        ///// converts data transfer object to data access objet
32        ///// </summary>
33        ///// <param name="source">data transfer object</param>
34        ///// <returns>data access object</returns>
35        //public static aspnet_Membership ToEntity(User source) {
36        //  if (source == null) return null;
37        //  return new aspnet_Membership() {
38        //    ApplicationId = source.ApplicationId,
39        //    UserId = source.Id,
40        //    Password = source.Password,
41        //    PasswordFormat = 1,
42        //    PasswordSalt = source.PasswordSalt,
43        //    Email = source.Email,
44        //    IsApproved = source.IsApproved,
45        //    IsLockedOut = source.IsLookedOut,
46        //    CreateDate = source.CreateDate,
47        //    LastLoginDate = source.LastLoginDate,
48        //    LastPasswordChangedDate = source.LastPasswordChangeDate,
49        //    LastLockoutDate = source.LastLockoutDate,
50        //    FailedPasswordAttemptCount = 0,
51        //    FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01),
52        //    FailedPasswordAnswerAttemptCount = 0,
53        //    FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01),
54        //    Comment = source.Comment
55        //  };
56        //}
57
58        /// <summary>
59        /// converts data access object to data transfer object
60        /// </summary>
61        /// <param name="source">data access object</param>
62        /// <returns>data transfer object</returns>
63        public static User ToDataTransfer(aspnet_User userSource, aspnet_Membership membershipSource)
64        {
65            if (userSource == null || membershipSource == null) return null;
66            return new User()
67            {
68                ApplicationId = userSource.ApplicationId,
69                Id = userSource.UserId,
70                Name = userSource.UserName,
71                //LoweredUserName = userSource.LoweredUserName,
72                //IsAnonymous = userSource.IsAnonymous,
73                LastActivityDate = userSource.LastActivityDate,
74                Password = membershipSource.Password,
75                PasswordSalt = membershipSource.PasswordSalt,
76                Email = membershipSource.Email,
77                IsApproved = membershipSource.IsApproved,
78                IsLookedOut = membershipSource.IsApproved,
79                CreateDate = membershipSource.CreateDate,
80                LastLoginDate = membershipSource.LastLoginDate,
81                LastPasswordChangeDate = membershipSource.LastPasswordChangedDate,
82                LastLockoutDate = membershipSource.LastLockoutDate,
83                Comment = membershipSource.Comment
84            };
85        }
86
87        /// <summary>
88        /// converts data transfer object to data access object
89        /// </summary>
90        /// <param name="source">data transfer object</param>
91        /// <param name="target">data access object</param>
92        public static void ToEntity(User source, aspnet_User userTarget, aspnet_Membership membershipTarget)
93        {
94            if ((source != null) && (userTarget != null) && (membershipTarget != null))
95            {
96              userTarget.ApplicationId = source.ApplicationId;
97              membershipTarget.ApplicationId = source.ApplicationId;
98              userTarget.UserId = source.Id;
99              membershipTarget.UserId = source.Id;
100              userTarget.UserName = source.Name;
101              userTarget.LoweredUserName = source.Name;
102              userTarget.IsAnonymous = false;
103              userTarget.LastActivityDate = source.LastActivityDate;
104              membershipTarget.Password = source.Password;
105              membershipTarget.PasswordFormat = 1;
106              membershipTarget.PasswordSalt = source.PasswordSalt;
107              membershipTarget.Email = source.Email;
108              membershipTarget.IsApproved = source.IsApproved;
109              membershipTarget.IsLockedOut = source.IsLookedOut;
110              membershipTarget.CreateDate = source.CreateDate;
111              membershipTarget.LastLoginDate = source.LastLoginDate;
112              membershipTarget.LastPasswordChangedDate = source.LastPasswordChangeDate;
113              membershipTarget.LastLockoutDate = source.LastLockoutDate;
114              membershipTarget.FailedPasswordAttemptCount = 0;
115              membershipTarget.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01);
116              membershipTarget.FailedPasswordAnswerAttemptCount = 0;
117              membershipTarget.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01);
118              membershipTarget.Comment = source.Comment;
119
120            }
121
122        }
123
124
125        #endregion
126
127        #region Application
128
129        ///// <summary>
130        ///// converts data transfer object to data access objet
131        ///// </summary>
132        ///// <param name="source">data transfer object</param>
133        ///// <returns>data access object</returns>
134        //public static aspnet_Application ToEntity(Application source)
135        //{
136        //    if (source == null) return null;
137        //    return new aspnet_Application()
138        //    {
139        //        ApplicationId = source.ApplicationId,
140        //        ApplicationName = source.ApplicationName,
141        //        LoweredApplicationName = source.LoweredApplicationName,
142        //        Description = source.Description
143        //    };
144        //}
145
146        ///// <summary>
147        ///// converts data access object to data transfer object
148        ///// </summary>
149        ///// <param name="source">data access object</param>
150        ///// <returns>data transfer object</returns>
151        //public static Application ToDataTransfer(aspnet_Application source)
152        //{
153        //    if (source == null) return null;
154        //    return new Application()
155        //    {
156        //        ApplicationId = source.ApplicationId,
157        //        ApplicationName = source.ApplicationName,
158        //        LoweredApplicationName = source.LoweredApplicationName,
159        //        Description = source.Description
160        //    };
161        //}
162
163        ///// <summary>
164        ///// converts data transfer object to data access object
165        ///// </summary>
166        ///// <param name="source">data transfer object</param>
167        ///// <param name="target">data access object</param>
168        //public static void ToEntity(Application source, aspnet_Application target)
169        //{
170        //    if ((source != null) && (target != null))
171        //    {
172        //        target.ApplicationId = source.ApplicationId;
173        //        target.ApplicationName = source.ApplicationName;
174        //        target.LoweredApplicationName = source.LoweredApplicationName;
175        //        target.Description = source.Description;
176        //    }
177
178        //}
179
180        #endregion
181
182        #region Membership
183
184        ///// <summary>
185        ///// converts data transfer object to data access objet
186        ///// </summary>
187        ///// <param name="source">data transfer object</param>
188        ///// <returns>data access object</returns>
189        //public static aspnet_Membership ToEntity(Membership source)
190        //{
191        //    if (source == null) return null;
192        //    return new aspnet_Membership()
193        //    {
194        //        ApplicationId = source.ApplicationId,
195        //        UserId = source.UserId,
196        //        Password = source.Password,
197        //        PasswordAnswer = source.PasswordAnswer,
198        //        PasswordSalt = source.PasswordSalt,
199        //        PasswordQuestion = source.PasswordQuestion,
200               
201        //        Email = source.Email,
202        //        LoweredEmail = source.LoweredEmail,
203        //        IsApproved = source.IsApproved,
204        //        IsLockedOut = source.IsLockedOut,
205        //        CreateDate = source.CreateDate,
206        //        LastLoginDate = source.LastLoginDate,
207        //        LastPasswordChangedDate = source.LastPasswordChangedDate,
208        //        LastLockoutDate = source.LastLockoutDate,
209        //        Comment = source.Comment
210
211               
212        //    };
213        //}
214
215        ///// <summary>
216        ///// converts data access object to data transfer object
217        ///// </summary>
218        ///// <param name="source">data access object</param>
219        ///// <returns>data transfer object</returns>
220        //public static Membership ToDataTransfer(aspnet_Membership source)
221        //{
222        //    if (source == null) return null;
223        //    return new Membership()
224        //    {
225        //        ApplicationId = source.ApplicationId,
226        //        UserId = source.UserId,
227        //        Password = source.Password,
228        //        PasswordAnswer = source.PasswordAnswer,
229        //        PasswordSalt = source.PasswordSalt,
230        //        PasswordQuestion = source.PasswordQuestion,
231               
232        //        Email = source.Email,
233        //        LoweredEmail = source.LoweredEmail,
234        //        IsApproved = source.IsApproved,
235        //        IsLockedOut = source.IsLockedOut,
236        //        CreateDate = source.CreateDate,
237        //        LastLoginDate = source.LastLoginDate,
238        //        LastPasswordChangedDate = source.LastPasswordChangedDate,
239        //        LastLockoutDate = source.LastLockoutDate,
240        //        Comment = source.Comment
241        //    };
242        //}
243
244        ///// <summary>
245        ///// converts data transfer object to data access object
246        ///// </summary>
247        ///// <param name="source">data transfer object</param>
248        ///// <param name="target">data access object</param>
249        //public static void ToEntity(Membership source, aspnet_Membership target)
250        //{
251        //    if ((source != null) && (target != null))
252        //    {
253        //        target.ApplicationId = source.ApplicationId;
254        //        target.UserId = source.UserId;
255        //        target.Password = source.Password;
256        //        target.PasswordAnswer = source.PasswordAnswer;
257        //        target.PasswordSalt = source.PasswordSalt;
258        //        target.PasswordQuestion = source.PasswordQuestion;
259               
260        //        target.Email = source.Email;
261        //        target.LoweredEmail = source.LoweredEmail;
262        //        target.IsApproved = source.IsApproved;
263        //        target.IsLockedOut = source.IsLockedOut;
264        //        target.CreateDate = source.CreateDate;
265        //        target.LastLoginDate = source.LastLoginDate;
266        //        target.LastPasswordChangedDate = source.LastPasswordChangedDate;
267        //        target.LastLockoutDate = source.LastLockoutDate;
268        //        target.Comment = source.Comment;
269        //    }
270
271        //}
272
273        #endregion
274
275        #region Role
276
277        ///// <summary>
278        ///// converts data transfer object to data access objet
279        ///// </summary>
280        ///// <param name="source">data transfer object</param>
281        ///// <returns>data access object</returns>
282        //public static aspnet_Role ToEntity(Role source)
283        //{
284        //    if (source == null) return null;
285        //    return new aspnet_Role()
286        //    {
287        //        ApplicationId = source.ApplicationId,
288        //        RoleId = source.RoleId,
289        //        RoleName = source.RoleName,
290        //        LoweredRoleName = source.LoweredRoleName,
291        //        Description = source.Description
292        //    };
293        //}
294
295        ///// <summary>
296        ///// converts data access object to data transfer object
297        ///// </summary>
298        ///// <param name="source">data access object</param>
299        ///// <returns>data transfer object</returns>
300        //public static Role ToDataTransfer(aspnet_Role source)
301        //{
302        //    if (source == null) return null;
303        //    return new Role()
304        //    {
305        //        ApplicationId = source.ApplicationId,
306        //        RoleId = source.RoleId,
307        //        RoleName = source.RoleName,
308        //        LoweredRoleName = source.LoweredRoleName,
309        //        Description = source.Description
310        //    };
311        //}
312
313        ///// <summary>
314        ///// converts data transfer object to data access object
315        ///// </summary>
316        ///// <param name="source">data transfer object</param>
317        ///// <param name="target">data access object</param>
318        //public static void ToEntity(Role source, aspnet_Role target)
319        //{
320        //    if ((source != null) && (target != null))
321        //    {
322        //        target.ApplicationId = source.ApplicationId;
323        //        target.RoleId = source.RoleId;
324        //        target.RoleName = source.RoleName;
325        //        target.LoweredRoleName = source.LoweredRoleName;
326        //        target.Description = source.Description;
327        //    }
328
329        //}
330
331        #endregion
332
333    }
334}
Note: See TracBrowser for help on using the repository browser.