using HeuristicLab.Services.Authentication.DataAccess; using HeuristicLab.Services.Authentication.DataTransfer; namespace HeuristicLab.Services.Authentication { public class Convert { #region User /// /// converts data access object to data transfer object /// /// data access object /// data transfer object public static User ToDataTransfer(aspnet_User userSource, aspnet_Membership membershipSource) { if (userSource == null || membershipSource == null) return null; return new User() { ApplicationId = userSource.ApplicationId, Id = userSource.UserId, Name = userSource.UserName, //LoweredUserName = userSource.LoweredUserName, //IsAnonymous = userSource.IsAnonymous, LastActivityDate = userSource.LastActivityDate, Password = membershipSource.Password, PasswordSalt = membershipSource.PasswordSalt, Email = membershipSource.Email, IsApproved = membershipSource.IsApproved, IsLookedOut = membershipSource.IsApproved, CreateDate = membershipSource.CreateDate, LastLoginDate = membershipSource.LastLoginDate, LastPasswordChangeDate = membershipSource.LastPasswordChangedDate, LastLockoutDate = membershipSource.LastLockoutDate, Comment = membershipSource.Comment }; } /// /// converts data transfer object to data access object /// /// data transfer object /// data access object public static void ToEntity(User source, aspnet_User userTarget, aspnet_Membership membershipTarget) { if ((source != null) && (userTarget != null) && (membershipTarget != null)) { userTarget.ApplicationId = source.ApplicationId; membershipTarget.ApplicationId = source.ApplicationId; userTarget.UserId = source.Id; membershipTarget.UserId = source.Id; userTarget.UserName = source.Name; userTarget.LoweredUserName = source.Name; userTarget.IsAnonymous = false; userTarget.LastActivityDate = source.LastActivityDate; membershipTarget.Password = source.Password; membershipTarget.PasswordFormat = 1; membershipTarget.PasswordSalt = source.PasswordSalt; membershipTarget.Email = source.Email; membershipTarget.IsApproved = source.IsApproved; membershipTarget.IsLockedOut = source.IsLookedOut; membershipTarget.CreateDate = source.CreateDate; membershipTarget.LastLoginDate = source.LastLoginDate; membershipTarget.LastPasswordChangedDate = source.LastPasswordChangeDate; membershipTarget.LastLockoutDate = source.LastLockoutDate; membershipTarget.FailedPasswordAttemptCount = 0; membershipTarget.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01); membershipTarget.FailedPasswordAnswerAttemptCount = 0; membershipTarget.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01); membershipTarget.Comment = source.Comment; } } #endregion #region Application /// /// converts data access object to data transfer object /// /// data access object /// data transfer object public static Application ToDataTransfer(aspnet_Application source) { if (source == null) return null; return new Application() { Id = source.ApplicationId, Name = source.ApplicationName, //LoweredApplicationName = source.LoweredApplicationName, Description = source.Description }; } /// /// converts data transfer object to data access object /// /// data transfer object /// data access object public static void ToEntity(Application source, aspnet_Application target) { if ((source != null) && (target != null)) { target.ApplicationId = source.Id; target.ApplicationName = source.Name; target.LoweredApplicationName = source.Name.ToLower(); target.Description = source.Description; } } #endregion #region Role /// /// converts data access object to data transfer object /// /// data access object /// data transfer object public static Role ToDataTransfer(aspnet_Role source) { if (source == null) return null; return new Role() { ApplicationId = source.ApplicationId, Id = source.RoleId, Name = source.RoleName, Description = source.Description, //LoweredRoleName = source.LoweredRoleName, }; } /// /// converts data transfer object to data access object /// /// data transfer object /// data access object public static void ToEntity(Role source, aspnet_Role target) { if ((source != null) && (target != null)) { target.ApplicationId = source.ApplicationId; target.RoleId = source.Id; target.RoleName = source.Name; target.LoweredRoleName = source.Name.ToLower(); target.Description = source.Description; } } #endregion } }