private void loadResults(User student) { if (student == null) return; resultQuizContext.QuizResults.Clear(); resultQuizContext.Load(resultQuizContext.GetQuizResultsForUserQuery(student.UserId)); RaisePropertyChanged("QuizResults"); }
/// <summary> /// Устаревший метод для добавления новых объектов в набор EntitySet Users. Взамен можно использовать метод .Add связанного свойства ObjectSet<T>. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
private void OKButton_Click(object sender, RoutedEventArgs e) { //if (this.ValidateItem()) { this.registrationData.Email = textBoxUserEmail.Text; this.registrationData.UserName = textBoxUserLogin.Text; registrationData.Question = "1?"; registrationData.Answer = "1"; MRZS.Web.Models.User user = new MRZS.Web.Models.User(); registrationData.FirstName = textBoxFirstName.Text; registrationData.LastName = textBoxLastName.Text; if (comboBoxUserRole.SelectedIndex > 0) { registrationData.UserRole = (comboBoxUserRole.SelectedValue as aspnet_Roles).RoleName; } var gr = comboBoxUserGroup.SelectedValue as Group; if (gr != null) { registrationData.GroupId = gr.GroupId; } this.registrationData.CurrentOperation = this.userRegistrationContext.CreateUser( this.registrationData, this.registrationData.Password, this.RegistrationOperation_Completed, null); } }
/// <summary> /// Создание нового объекта User. /// </summary> /// <param name="userId">Исходное значение свойства UserId.</param> /// <param name="aspnet_UserId">Исходное значение свойства aspnet_UserId.</param> public static User CreateUser(global::System.Int32 userId, global::System.Guid aspnet_UserId) { User user = new User(); user.UserId = userId; user.aspnet_UserId = aspnet_UserId; return user; }
public CreateUserStatus CreateUser(RegistrationData user, [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof (ValidationErrorResources))] [StringLength(50, MinimumLength = 1, ErrorMessageResourceName = "ValidationErrorBadPasswordLength", ErrorMessageResourceType = typeof (ValidationErrorResources))] string password) { if (user == null) { throw new ArgumentNullException("user"); } // Run this BEFORE creating the user to make sure roles are enabled and the default role // will be available // // If there are a problem with the role manager it is better to fail now than to have it // happening after the user is created if (!Roles.RoleExists(DefaultRole)) { Roles.CreateRole(DefaultRole); } // NOTE: ASP.NET by default uses SQL Server Express to create the user database. // CreateUser will fail if you do not have SQL Server Express installed. MembershipCreateStatus createStatus; Membership.CreateUser(user.UserName, password, user.Email, user.Question, user.Answer, true, null, out createStatus); if (createStatus != MembershipCreateStatus.Success) { return ConvertStatus(createStatus); } var model = new MRZSEntities(); aspnet_Users createdUser = model.aspnet_Users.SingleOrDefault(u => u.UserName == user.UserName); var adUser = new Models.User(); adUser.FirstName = user.FirstName; adUser.LastName = user.LastName; adUser.aspnet_UserId = createdUser.UserId; if (user.GroupId > 0) { adUser.GroupId = user.GroupId; } model.Users.AddObject(adUser); model.SaveChanges(); // Assign it to the default role // This *can* fail but only if role management is disabled if (!string.IsNullOrEmpty(user.UserRole)) Roles.AddUserToRole(user.UserName, user.UserRole); // Set its friendly name (profile setting) // This *can* fail but only if Web.config is configured incorrectly ProfileBase profile = ProfileBase.Create(user.UserName, true); profile.SetPropertyValue("FriendlyName", user.FriendlyName); profile.Save(); return CreateUserStatus.Success; }