/// <summary>
        /// Converts the Rem2Membership user to DB user.
        /// </summary>
        /// <returns></returns>
        public User ToDBUser()
        {
            User u = new User()
            {
                UserName = this.UserName,
                Email = this.Email,
                FirstName = this.FirstName,
                LastName = this.LastName
            };

            if (ProviderUserKey is int)
                u.idUser = (int)ProviderUserKey;

            return u;
        }
 /// <summary>
 /// Initializes a new instance of Rem2MembershipUser from a DB user.
 /// </summary>
 /// <param name="providerName">The System.Web.Security.MembershipUser.ProviderName string for the membership user.</param>
 /// <param name="u">The DB user.</param>
 public Rem2MembershipUser(string providerName, User u)
     : this(providerName, u.UserName, u.idUser, u.Email, null, null, true, false, default(DateTime),
     default(DateTime), default(DateTime), default(DateTime), default(DateTime), u.FirstName, u.LastName)
 {
 }
        /// <summary>
        /// Creates a new user and inserts him into the DB.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">User password.</param>
        /// <param name="email">E-mail address.</param>
        /// <param name="firstName">First name.</param>
        /// <param name="lastName">Last name.</param>
        /// <param name="status">User creation status.</param>
        /// <returns>A new Membership user if successful, null otherwise.</returns>
        public Rem2MembershipUser CreateUser(string userName, string password, string email,
            string firstName, string lastName, out MembershipCreateStatus status)
        {
            Reminder2DataContext ctx = new Reminder2DataContext();

            //check user name
            if (string.IsNullOrEmpty(userName))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return null;
            }

            //check if the user already exists
            if (ctx.Users.FirstOrDefault(u => u.UserName == userName) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }

            Rem2MembershipUser memUser = null;
            try
            {
                User dbUser = new User()
                {
                    UserName = userName,
                    Password = password,
                    Email = email,
                    FirstName = firstName,
                    LastName = lastName
                };
                ctx.Users.InsertOnSubmit(dbUser);
                ctx.SubmitChanges();
                memUser = new Rem2MembershipUser(this.Name, dbUser);
            }
            catch
            {
                status = MembershipCreateStatus.ProviderError;
                return null;
            }

            status = MembershipCreateStatus.Success;
            return memUser;
        }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);