//********************************************************** //* Создание пользователя //********************************************************** 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); } }
partial void DeleteUser(User instance);
partial void UpdateUser(User instance);
partial void InsertUser(User instance);
private void detach_Users(User entity) { this.SendPropertyChanging(); entity.UsersInRole = null; }
private void attach_Users(User entity) { this.SendPropertyChanging(); entity.UsersInRole = this; }