protected void lbSubmit_Click(object sender, EventArgs e) { //save the room var rc = new RoomController(); if (txtRoomId.Text.Any()) { var r = rc.GetRoom(new Guid(txtRoomId.Text), ModuleId); r.RoomName = txtRoomName.Text.Trim(); r.RoomDescription = txtRoomDescription.Text.Trim(); r.RoomPassword = txtRoomPassword.Text.Trim(); r.RoomWelcome = txtRoomWelcome.Text.Trim(); r.Private = chkPrivateRoom.Checked; r.Enabled = chkEnabled.Checked; r.LastUpdatedByUserId = UserId; r.LastUpdatedDate = DateTime.UtcNow; rc.UpdateRoom(r); } else { var r = new Room { RoomId = Guid.NewGuid(), RoomName = txtRoomName.Text.Trim(), RoomDescription = txtRoomDescription.Text.Trim(), RoomPassword = txtRoomPassword.Text.Trim(), RoomWelcome = txtRoomWelcome.Text.Trim(), Private = chkPrivateRoom.Checked, Enabled = chkEnabled.Checked, CreatedByUserId = UserId, CreatedDate = DateTime.UtcNow, LastUpdatedByUserId = UserId, LastUpdatedDate = DateTime.UtcNow, ModuleId = ModuleId }; rc.CreateRoom(r); } Response.Redirect(DotNetNuke.Common.Globals.NavigateURL()); }
//check to see if there is a string in the message that is too many characters put together private string ParseMessage(string message, Guid roomId) { //not using REGEX for now, maybe in the future //Regex nameChangeRegex = new Regex(@"/nick[^/]+", RegexOptions.IgnoreCase); //var nameChangeMatch = nameChangeRegex.Match(message); ////clean out all "scope" parameters from DNN Forum urls //if (nameChangeMatch.Success) //{ // //change the name // string newName = message.Split(':')[1]; // message = UpdateName(newName.Trim()); //} //TODO: allow command for Updating room description/properties //http://www.irchelp.org/irchelp/changuide.html //allow for Room creation/joining if (message.ToLower().StartsWith("/join")) { var userId = -1; if (Convert.ToInt32(Clients.Caller.userid) > 0) { userId = Convert.ToInt32(Clients.Caller.userid); } if (userId > 0) { string roomName = message.Remove(0, 5).Trim(); if (roomName.Length > 25) { Clients.Caller.newMessageNoParse(new Message { AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), ConnectionId = "0", MessageDate = DateTime.UtcNow, MessageId = -1, MessageText = Localization.GetString("RoomNameTooLong.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorUserId = -1, RoomId = roomId }); return(string.Empty); } //create room else { var rc = new RoomController(); //Lookup existing Rooms var r = rc.GetRoom(roomName); //int.TryParse(Clients.Caller.moduleid, out moduleId); int moduleId = Convert.ToInt32(Clients.Caller.moduleid); if (r != null) { //todo: anything to do here? the room exists already if (r.Enabled == false) { //what if the room has been disabled? } } else { r = new Room { RoomId = Guid.NewGuid(), RoomName = roomName, RoomWelcome = Localization.GetString("DefaultRoomWelcome.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), RoomDescription = Localization.GetString("DefaultRoomDescription.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), ModuleId = moduleId, CreatedDate = DateTime.UtcNow, CreatedByUserId = userId, LastUpdatedByUserId = userId, LastUpdatedDate = DateTime.UtcNow, Enabled = true }; rc.CreateRoom(r); } //make a call to the client to add the room to their model, and join Clients.Caller.messageJoin(r); } } else { // if there is no username for the user don't let them post var m = new Message { ConnectionId = Context.ConnectionId, MessageDate = DateTime.UtcNow, MessageText = Localization.GetString("AnonymousJoinDenied.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorUserId = -1, RoomId = roomId }; Clients.Caller.newMessage(m); } message = string.Empty; } message = message.Replace(" ", " ").Replace(" ", " ").Trim(); //for name change, using starts with to see if they typed /nick in if (message.ToLower().StartsWith("/nick")) { string newName = message.Remove(0, 5); if (newName.Length > 25) { Clients.Caller.newMessageNoParse(new Message { AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), ConnectionId = "0", MessageDate = DateTime.UtcNow, MessageId = -1, MessageText = Localization.GetString("NameToolong.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorUserId = -1, RoomId = roomId }); newName = newName.Remove(25); } if (newName.Trim().Length > 0) { message = UpdateName(newName.Trim()); } } if (message.ToLower().Trim() == Localization.GetString("Test.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile)) { message = Localization.GetString("Test.Response", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile); } return(message); }