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