/// <summary>
 /// Método desusado para agregar un nuevo objeto al EntitySet users. Considere la posibilidad de usar el método .Add de la propiedad ObjectSet&lt;T&gt; asociada.
 /// </summary>
 public void AddTousers(user user)
 {
     base.AddObject("users", user);
 }
 /// <summary>
 /// Crear un nuevo objeto user.
 /// </summary>
 /// <param name="idUsers">Valor inicial de la propiedad IdUsers.</param>
 /// <param name="userName">Valor inicial de la propiedad UserName.</param>
 /// <param name="password">Valor inicial de la propiedad Password.</param>
 public static user Createuser(global::System.Int32 idUsers, global::System.String userName, global::System.String password)
 {
     user user = new user();
     user.IdUsers = idUsers;
     user.UserName = userName;
     user.Password = password;
     return user;
 }
Exemplo n.º 3
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            using (dbmysqlEntities db = new dbmysqlEntities(cnnstring))
            {
                user usr = db.users.Where(u => u.UserName == username).FirstOrDefault();
                if (usr == null)
                {
                    usr = new user()
                    {
                        UserName = username,
                        Password = GetSHA1(password)
                    };

                    try
                    {
                        db.users.AddObject(usr);
                        db.SaveChanges();

                        MembershipUser msUser = new MembershipUser("MySQLMembershipProvider", usr.UserName, providerUserKey, usr.UserName + "@dxstudio.net", string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
                        status = MembershipCreateStatus.Success;
                        return msUser;
                    }
                    catch (Exception ex)
                    {
                        //Verificamos que efectivamente no se cree el usuario
                        usr = db.users.Where(u => u.UserName == username).FirstOrDefault();
                        if (usr != null)
                        {
                            db.users.DeleteObject(usr);
                            db.SaveChanges();
                        }
                        status = MembershipCreateStatus.UserRejected;
                        return null;
                    }
                }
                else
                {
                    MembershipUser msUser = new MembershipUser("MySQLMembershipProvider", usr.UserName, providerUserKey, usr.UserName + "@dxstudio.net", string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
                    status = MembershipCreateStatus.DuplicateUserName;
                    return msUser;
                }
            }
        }