Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
 partial void DeleteUser(User instance);
Exemplo n.º 3
0
 partial void UpdateUser(User instance);
Exemplo n.º 4
0
 partial void InsertUser(User instance);
Exemplo n.º 5
0
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.UsersInRole = null;
		}
Exemplo n.º 6
0
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.UsersInRole = this;
		}