public User CreateUser(string name) { if (!IsValidUsername(name)) { throw new ArgumentException("Usernames can contain unicode symbols, numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)"); } var dbContext = _dbProvider.CreateContext(); // TODO: Remove after user item data is migrated. var max = dbContext.Users.Any() ? dbContext.Users.Select(u => u.InternalId).Max() : 0; var newUser = new User( name, _defaultAuthenticationProvider.GetType().FullName, _defaultPasswordResetProvider.GetType().FullName) { InternalId = max + 1 }; dbContext.Users.Add(newUser); dbContext.SaveChanges(); OnUserCreated?.Invoke(this, new GenericEventArgs <User>(newUser)); return(newUser); }
private void createButton_Click(object sender, RoutedEventArgs e) { // try to create a new user when the user clicks the button // validate input data if (string.IsNullOrEmpty(usernameInput.Text) || dateInput.SelectedDate == null) { headerText.Content = "Please input a name and date!"; return; } else { // try to create a new user // if it works: fire the OnUserCreated event // if not: change the header textblock UserModel newUser = new UserModel() { name = usernameInput.Text, birthday = (DateTime)dateInput.SelectedDate }; if (dataAccess.createUser(newUser)) { OnUserCreated?.Invoke(); } else { headerText.Content = "ERROR: could not create user"; } } }
public async Task <User> CreateUserAsync(string name) { if (!IsValidUsername(name)) { throw new ArgumentException("Usernames can contain unicode symbols, numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)"); } using var dbContext = _dbProvider.CreateContext(); var newUser = await CreateUserInternalAsync(name, dbContext).ConfigureAwait(false); dbContext.Users.Add(newUser); await dbContext.SaveChangesAsync().ConfigureAwait(false); OnUserCreated?.Invoke(this, new GenericEventArgs <User>(newUser)); return(newUser); }
/// <summary> /// Handles incoming <see cref="UserUpdatePacket"/>s. /// </summary> /// <param name="connectionId">Original connection ID</param> /// <param name="packet">Incoming <see cref="UserUpdatePacket"/></param> private void userUpdatePacketHandler(string connectionId, UserUpdatePacket packet) { User user = packet.User; lock (userStoreLock) { // Check if the user does not already exist if (!userStore.Users.ContainsKey(user.Uuid)) { // Add the user userStore.Users.Add(user.Uuid, user); // Raise the user created event and return OnUserCreated?.Invoke(this, new UserCreatedEventArgs(user.Uuid, user.LoggedIn, user.DisplayName)); return; } // Hold on to the existing copy for later User existingUser = userStore.Users[user.Uuid]; // Replace the user with the new copy userStore.Users[user.Uuid] = user; // Compare the user's login states and raise an event if they differ if (user.LoggedIn != existingUser.LoggedIn) { if (user.LoggedIn) { OnUserLoggedIn?.Invoke(this, new UserLoginStateChangedEventArgs(user.Uuid, false, true)); } else { OnUserLoggedOut?.Invoke(this, new UserLoginStateChangedEventArgs(user.Uuid, true, false)); } } // Compare the user's display name and raise an event if they differ if (user.DisplayName != existingUser.DisplayName) { OnUserDisplayNameChanged?.Invoke(this, new UserDisplayNameChangedEventArgs(user.Uuid, existingUser.DisplayName, user.DisplayName)); } } }
public void DispatchUserCreatedEvent(SimpleUser simpleUser) { OnUserCreated?.Invoke(this, new UserCreatedEventArgs(simpleUser)); }
public void Register(SocketUser user) { registry.Add(user.Id); OnUserCreated?.Invoke(this, new UserId(user)); }