Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5119 was 4979, checked in by jwolfing, 14 years ago

#1196 Changed BaseClasses in Data Transfer Objects, added Methods to User and Role ServiceClasses

File size: 6.4 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 access object to data transfer object
13        /// </summary>
14        /// <param name="source">data access object</param>
15        /// <returns>data transfer object</returns>
16        public static User ToDataTransfer(aspnet_User userSource, aspnet_Membership membershipSource)
17        {
18            if (userSource == null || membershipSource == null) return null;
19            return new User()
20            {
21                ApplicationId = userSource.ApplicationId,
22                Id = userSource.UserId,
23                Name = userSource.UserName,
24                //LoweredUserName = userSource.LoweredUserName,
25                //IsAnonymous = userSource.IsAnonymous,
26                LastActivityDate = userSource.LastActivityDate,
27                Password = membershipSource.Password,
28                PasswordSalt = membershipSource.PasswordSalt,
29                Email = membershipSource.Email,
30                IsApproved = membershipSource.IsApproved,
31                IsLookedOut = membershipSource.IsApproved,
32                CreateDate = membershipSource.CreateDate,
33                LastLoginDate = membershipSource.LastLoginDate,
34                LastPasswordChangeDate = membershipSource.LastPasswordChangedDate,
35                LastLockoutDate = membershipSource.LastLockoutDate,
36                Comment = membershipSource.Comment
37            };
38        }
39
40        /// <summary>
41        /// converts data transfer object to data access object
42        /// </summary>
43        /// <param name="source">data transfer object</param>
44        /// <param name="target">data access object</param>
45        public static void ToEntity(User source, aspnet_User userTarget, aspnet_Membership membershipTarget)
46        {
47            if ((source != null) && (userTarget != null) && (membershipTarget != null))
48            {
49                userTarget.ApplicationId = source.ApplicationId;
50                membershipTarget.ApplicationId = source.ApplicationId;
51                userTarget.UserId = source.Id;
52                membershipTarget.UserId = source.Id;
53                userTarget.UserName = source.Name;
54                userTarget.LoweredUserName = source.Name;
55                userTarget.IsAnonymous = false;
56                userTarget.LastActivityDate = source.LastActivityDate;
57                membershipTarget.Password = source.Password;
58                membershipTarget.PasswordFormat = 1;
59                membershipTarget.PasswordSalt = source.PasswordSalt;
60                membershipTarget.Email = source.Email;
61                membershipTarget.IsApproved = source.IsApproved;
62                membershipTarget.IsLockedOut = source.IsLookedOut;
63                membershipTarget.CreateDate = source.CreateDate;
64                membershipTarget.LastLoginDate = source.LastLoginDate;
65                membershipTarget.LastPasswordChangedDate = source.LastPasswordChangeDate;
66                membershipTarget.LastLockoutDate = source.LastLockoutDate;
67                membershipTarget.FailedPasswordAttemptCount = 0;
68                membershipTarget.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01);
69                membershipTarget.FailedPasswordAnswerAttemptCount = 0;
70                membershipTarget.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01);
71                membershipTarget.Comment = source.Comment;
72
73            }
74
75        }
76
77
78        #endregion
79
80        #region Application
81
82        /// <summary>
83        /// converts data access object to data transfer object
84        /// </summary>
85        /// <param name="source">data access object</param>
86        /// <returns>data transfer object</returns>
87        public static Application ToDataTransfer(aspnet_Application source)
88        {
89            if (source == null) return null;
90            return new Application()
91            {
92                Id = source.ApplicationId,
93                Name = source.ApplicationName,
94                //LoweredApplicationName = source.LoweredApplicationName,
95                Description = source.Description
96            };
97        }
98
99        /// <summary>
100        /// converts data transfer object to data access object
101        /// </summary>
102        /// <param name="source">data transfer object</param>
103        /// <param name="target">data access object</param>
104        public static void ToEntity(Application source, aspnet_Application target)
105        {
106            if ((source != null) && (target != null))
107            {
108                target.ApplicationId = source.Id;
109                target.ApplicationName = source.Name;
110                target.LoweredApplicationName = source.Name.ToLower();
111                target.Description = source.Description;
112            }
113
114        }
115
116        #endregion
117
118        #region Role
119
120        /// <summary>
121        /// converts data access object to data transfer object
122        /// </summary>
123        /// <param name="source">data access object</param>
124        /// <returns>data transfer object</returns>
125        public static Role ToDataTransfer(aspnet_Role source)
126        {
127            if (source == null) return null;
128            return new Role()
129            {
130                ApplicationId = source.ApplicationId,
131                Id = source.RoleId,
132                Name = source.RoleName,
133                Description = source.Description,
134                //LoweredRoleName = source.LoweredRoleName,
135            };
136        }
137
138        /// <summary>
139        /// converts data transfer object to data access object
140        /// </summary>
141        /// <param name="source">data transfer object</param>
142        /// <param name="target">data access object</param>
143        public static void ToEntity(Role source, aspnet_Role target)
144        {
145            if ((source != null) && (target != null))
146            {
147                target.ApplicationId = source.ApplicationId;
148                target.RoleId = source.Id;
149                target.RoleName = source.Name;
150                target.LoweredRoleName = source.Name.ToLower();
151                target.Description = source.Description;
152            }
153
154        }
155
156        #endregion
157
158    }
159}
Note: See TracBrowser for help on using the repository browser.