protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; Guid providerKey = (Guid)Membership.GetUser().ProviderUserKey; int roomID = RoomController.NextRoomID(); // Check to see if user is new var profiles = new UserProfileRepository().All(); if (!profiles.Select(x => x.aspUserID).Contains(providerKey)) { // UserProfile not found, create new UserProfileController.CreateUserProfile(providerKey, DateTime.Now.ToUniversalTime(), 0, roomID); CurrentUser cUser = CurrentUser.Instance; cUser.ResetCurrentUser(); cUser.RoomID = roomID; cUser.UpdateRoomID(roomID); SendWelcomeMessage(roomID); UpdateMessages(); } else { // UserProfile exists, update profile CurrentUser cUser = CurrentUser.Instance; cUser.ResetCurrentUser(); cUser.RoomID = roomID; cUser.UpdateRoomID(roomID); SendWelcomeMessage(roomID); UpdateMessages(); } MessageInput.Focus(); }