Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5010 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
RevLine 
[4590]1using HeuristicLab.Services.Authentication.DataAccess;
[4584]2using HeuristicLab.Services.Authentication.DataTransfer;
3
4namespace HeuristicLab.Services.Authentication
5{
6    public class Convert
7    {
8
9        #region User
10
[4588]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>
[4740]16        public static User ToDataTransfer(aspnet_User userSource, aspnet_Membership membershipSource)
[4584]17        {
[4740]18            if (userSource == null || membershipSource == null) return null;
[4588]19            return new User()
20            {
[4740]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
[4588]37            };
[4584]38        }
39
[4588]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>
[4740]45        public static void ToEntity(User source, aspnet_User userTarget, aspnet_Membership membershipTarget)
[4588]46        {
[4740]47            if ((source != null) && (userTarget != null) && (membershipTarget != null))
[4588]48            {
[4926]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;
[4740]72
[4588]73            }
74
75        }
76
77
[4584]78        #endregion
79
[4588]80        #region Application
81
[4926]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,
[4979]94                //LoweredApplicationName = source.LoweredApplicationName,
[4926]95                Description = source.Description
96            };
97        }
[4590]98
[4926]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;
[4979]110                target.LoweredApplicationName = source.Name.ToLower();
[4926]111                target.Description = source.Description;
112            }
[4590]113
[4926]114        }
[4590]115
[4588]116        #endregion
117
118        #region Role
119
[4926]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,
[4979]134                //LoweredRoleName = source.LoweredRoleName,
[4926]135            };
136        }
[4588]137
[4926]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;
[4979]150                target.LoweredRoleName = source.Name.ToLower();
[4926]151                target.Description = source.Description;
152            }
[4588]153
[4926]154        }
[4590]155
[4588]156        #endregion
157
[4584]158    }
159}
Note: See TracBrowser for help on using the repository browser.