예제 #1
0
        //**********************************************************
        //* Создание пользователя
        //**********************************************************
        public static MembershipUser CreateUser(String username, String password, Int32 roleId)
        {
            using (SandBoxDataContext db = new SandBoxDataContext())
            {
                var users = UserManager.GetUsers();
                if (Enumerable.Any(users, us => us.Login == username)) return null;

                User user = new User
                {
                    Login = username,
                    Password = password,
                    PasswordSalt = CreateSalt(),
                    CreatedDate = DateTime.Now,
                    LastLoginDate = DateTime.Now
                };
                user.Password = CreatePasswordHash(password, user.PasswordSalt);
                db.Users.InsertOnSubmit(user);
                db.SubmitChanges();

                var usr = db.Users.FirstOrDefault(x => x.Login == username);
                if (usr == null) return null;

                UsersInRole userInRole = new UsersInRole {UserId = usr.UserId, RoleId = roleId};
                db.UsersInRoles.InsertOnSubmit(userInRole);
                db.SubmitChanges();

                return GetUser(username);
            }
        }
예제 #2
0
 public static void EditUser(Int32 userid, String username, String login, String password, Int32 roleId, Int32 roleId2)
 {
     using (SandBoxDataContext db = new SandBoxDataContext())
     {
         User user = db.Users.FirstOrDefault(x => x.UserId == userid);
         if (user == null) return;
         user.Login = login;
         user.UserName = username;
         if (password != String.Empty)
         {
             user.PasswordSalt = CreateSalt();
             user.Password = CreatePasswordHash(password, user.PasswordSalt);
         }
         var userinroles = from ur in db.UsersInRoles
                           where ur.UserId == user.UserId
                           select ur;
         foreach (UsersInRole userinrole in userinroles) db.UsersInRoles.DeleteOnSubmit(userinrole);
         UsersInRole userInRole = new UsersInRole { UserId = user.UserId, RoleId = roleId };
         db.UsersInRoles.InsertOnSubmit(userInRole);
         UsersInRole userInRole2 = new UsersInRole { UserId = user.UserId, RoleId = roleId2 };
         db.UsersInRoles.InsertOnSubmit(userInRole2);
         db.SubmitChanges();
     }
 }
예제 #3
0
 partial void UpdateUsersInRole(UsersInRole instance);
예제 #4
0
 partial void DeleteUsersInRole(UsersInRole instance);
예제 #5
0
 partial void InsertUsersInRole(UsersInRole instance);