public ActionResult Create(UserCreateViewModel model) { if (!db.Organizations.Any(o => o.OrganizationId == model.OrganizationId) || !AccessIsAllowed(model.OrganizationId)) ModelState.AddModelError("Error", "You are not authorized to add users"); if (GetLoggedInUser().RoleId > model.RoleId) ModelState.AddModelError("RoleId", "You are not authorized to add a user in this role"); if (ModelState.IsValid) { var user = new User { OrganizationId = model.OrganizationId, Username = model.Username, Password = PasswordHash.CreateHash(model.Password), RoleId = model.RoleId, Email = model.Email, Firstname = model.Firstname, Lastname = model.Lastname, Middlename = model.Middlename, Gender = model.Gender, GraduationYear = model.GraduationYear, EligibleForRaces = model.EligibleForRaces, DefaultVarsityLevelId = model.DefaultVarsityLevelId.HasValue ? (int?)model.DefaultVarsityLevelId.Value : null, DefaultRunnerClassificationId = model.DefaultRunnerClassificationId.HasValue ? (int?)model.DefaultRunnerClassificationId : null, CreatedBy = LoggedInUserId, }; db.Users.AddObject(user); TryDBChange(() => db.SaveChanges()); } model.RoleList = new SelectList(Role.GetRolesForOrganizationCreatableByRole(model.OrganizationId, GetLoggedInUser().RoleId), "RoleId", "RoleName"); model.RunnerClassifications = new SelectList(db.RunnerClassifications.ToList(), "RunnerClassificationId", "RunnerClassificationName"); model.VarsityLevels = new SelectList(db.VarsityLevels.ToList(), "VarsityLevelId", "VarsityLevelName"); return PartialView("CreateForm", model); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="roleId">Initial value of the RoleId property.</param> /// <param name="organizationId">Initial value of the OrganizationId property.</param> /// <param name="username">Initial value of the Username property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="firstname">Initial value of the Firstname property.</param> /// <param name="lastname">Initial value of the Lastname property.</param> /// <param name="eligibleForRaces">Initial value of the EligibleForRaces property.</param> /// <param name="gender">Initial value of the Gender property.</param> public static User CreateUser(global::System.Int64 userId, global::System.Int32 roleId, global::System.Int64 organizationId, global::System.String username, global::System.String password, global::System.String firstname, global::System.String lastname, global::System.Boolean eligibleForRaces, global::System.String gender) { User user = new User(); user.UserId = userId; user.RoleId = roleId; user.OrganizationId = organizationId; user.Username = username; user.Password = password; user.Firstname = firstname; user.Lastname = lastname; user.EligibleForRaces = eligibleForRaces; user.Gender = gender; return user; }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
public CCMembershipUser Initialize(User user) { return new CCMembershipUser( "CCMembershipProvider", user.Username, user.UserId, user.Email, "", false, false, Convert.ToDateTime(user.CreatedOn), DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, user.OrganizationId); }