#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Services.Authentication.DataAccess; using HeuristicLab.Services.Authentication.DataTransfer; namespace HeuristicLab.Services.Authentication { public class Convert { #region User public static User ToDto(aspnet_User sourceUser, aspnet_Membership sourceMembership) { if (sourceUser == null || sourceMembership == null) return null; return new User() { ApplicationId = sourceUser.ApplicationId, Id = sourceUser.UserId, Name = sourceUser.UserName, LastActivityDate = sourceUser.LastActivityDate, Email = sourceMembership.Email, IsApproved = sourceMembership.IsApproved, IsLookedOut = sourceMembership.IsApproved, CreateDate = sourceMembership.CreateDate, LastLoginDate = sourceMembership.LastLoginDate, LastPasswordChangeDate = sourceMembership.LastPasswordChangedDate, LastLockoutDate = sourceMembership.LastLockoutDate, Description = sourceMembership.Comment }; } public static void ToEntity(User sourceUser, aspnet_User targetUser, aspnet_Membership targetMembership) { if ((sourceUser != null) && (targetUser != null) && (targetMembership != null)) { targetUser.ApplicationId = sourceUser.ApplicationId; targetUser.UserId = sourceUser.Id; targetUser.UserName = sourceUser.Name; targetUser.LoweredUserName = sourceUser.Name; targetUser.IsAnonymous = false; targetUser.LastActivityDate = sourceUser.LastActivityDate; targetMembership.UserId = sourceUser.Id; targetMembership.ApplicationId = sourceUser.ApplicationId; targetMembership.PasswordFormat = 1; targetMembership.Email = sourceUser.Email; targetMembership.IsApproved = sourceUser.IsApproved; targetMembership.IsLockedOut = sourceUser.IsLookedOut; targetMembership.CreateDate = sourceUser.CreateDate; targetMembership.LastLoginDate = sourceUser.LastLoginDate; targetMembership.LastPasswordChangedDate = sourceUser.LastPasswordChangeDate; targetMembership.LastLockoutDate = sourceUser.LastLockoutDate; targetMembership.FailedPasswordAttemptCount = 0; targetMembership.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01); targetMembership.FailedPasswordAnswerAttemptCount = 0; targetMembership.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01); targetMembership.Comment = sourceUser.Description; } } public static void ToEntity(User source, out aspnet_User userTarget, out aspnet_Membership membershipTarget) { userTarget = new aspnet_User(); membershipTarget = new aspnet_Membership(); if ((source != null)) { userTarget.ApplicationId = source.ApplicationId; userTarget.UserId = source.Id; userTarget.UserName = source.Name; userTarget.LoweredUserName = source.Name; userTarget.IsAnonymous = false; userTarget.LastActivityDate = source.LastActivityDate; membershipTarget.UserId = source.Id; membershipTarget.ApplicationId = source.ApplicationId; membershipTarget.PasswordFormat = 1; 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.Description; } } #endregion #region Application public static Application ToDto(aspnet_Application sourceApplication) { if (sourceApplication == null) return null; return new Application() { Id = sourceApplication.ApplicationId, Name = sourceApplication.ApplicationName, Description = sourceApplication.Description }; } public static void ToEntity(Application sourceApplication, aspnet_Application targetApplication) { if ((sourceApplication != null) && (targetApplication != null)) { targetApplication.ApplicationId = sourceApplication.Id; targetApplication.ApplicationName = sourceApplication.Name; targetApplication.LoweredApplicationName = sourceApplication.Name.ToLower(); targetApplication.Description = sourceApplication.Description; } } public static aspnet_Application ToEntity(Application sourceApplication) { if (sourceApplication == null) return null; return new aspnet_Application() { ApplicationId = sourceApplication.Id, ApplicationName = sourceApplication.Name, LoweredApplicationName = sourceApplication.Name.ToLower(), Description = sourceApplication.Description }; } #endregion #region Role public static Role ToDto(aspnet_Role sourceRole) { if (sourceRole == null) return null; return new Role() { ApplicationId = sourceRole.ApplicationId, Id = sourceRole.RoleId, Name = sourceRole.RoleName, Description = sourceRole.Description, }; } public static void ToEntity(Role sourceRole, aspnet_Role targetRole) { if ((sourceRole != null) && (targetRole != null)) { targetRole.ApplicationId = sourceRole.ApplicationId; targetRole.RoleId = sourceRole.Id; targetRole.RoleName = sourceRole.Name; targetRole.LoweredRoleName = sourceRole.Name.ToLower(); targetRole.Description = sourceRole.Description; } } public static aspnet_Role ToEntity(Role sourceRole) { if (sourceRole == null) return null; return new aspnet_Role() { ApplicationId = sourceRole.ApplicationId, RoleId = sourceRole.Id, RoleName = sourceRole.Name, LoweredRoleName = sourceRole.Name.ToLower(), Description = sourceRole.Description, }; } #endregion } }