private async Task <ChatHubUser> OnConnectedUser(ChatHubUser chatHubUser) { ChatHubConnection ChatHubConnection = new ChatHubConnection() { ChatHubUserId = chatHubUser.UserId, ConnectionId = Context.ConnectionId, IpAddress = Context.GetHttpContext().Connection.RemoteIpAddress.ToString(), UserAgent = Context.GetHttpContext().Request.Headers["User-Agent"].ToString(), Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Active) }; ChatHubConnection = this.chatHubRepository.AddChatHubConnection(ChatHubConnection); ChatHubSettings ChatHubSetting = this.chatHubRepository.GetChatHubSettingByUser(chatHubUser); if (ChatHubSetting == null) { ChatHubSetting = new ChatHubSettings() { UsernameColor = "#7744aa", MessageColor = "#44aa77", ChatHubUserId = chatHubUser.UserId }; ChatHubSetting = this.chatHubRepository.AddChatHubSetting(ChatHubSetting); } return(chatHubUser); }
public ChatHubSettings CreateChatHubSettingClientModel(ChatHubSettings settings) { return(new ChatHubSettings() { UsernameColor = settings.UsernameColor, MessageColor = settings.MessageColor, CreatedOn = settings.CreatedOn, CreatedBy = settings.CreatedBy, ModifiedOn = settings.ModifiedOn, ModifiedBy = settings.ModifiedBy }); }
public ChatHubSettings UpdateChatHubSetting(ChatHubSettings ChatHubSetting) { try { db.Entry(ChatHubSetting).State = EntityState.Modified; db.SaveChanges(); return(ChatHubSetting); } catch { throw; } }
public ChatHubSettings AddChatHubSetting(ChatHubSettings ChatHubSetting) { try { db.ChatHubSetting.Add(ChatHubSetting); db.SaveChanges(); return(ChatHubSetting); } catch { throw; } }
public ChatHubUser CreateChatHubUserClientModel(ChatHubUser user) { List <ChatHubConnection> activeConnections = this.chatHubRepository.GetConnectionsByUserId(user.UserId).Active().ToList(); List <ChatHubConnection> activeConnectionsClientModels = activeConnections != null && !activeConnections.Any() ? new List <ChatHubConnection>() : activeConnections.Select(item => CreateChatHubConnectionClientModel(item)).ToList(); ChatHubSettings chatHubSettings = this.chatHubRepository.GetChatHubSetting(user.UserId); ChatHubSettings chatHubSettingsClientModel = chatHubSettings != null?this.CreateChatHubSettingClientModel(chatHubSettings) : null; return(new ChatHubUser() { UserId = user.UserId, Username = user.Username, DisplayName = user.DisplayName, Connections = activeConnectionsClientModels, Settings = chatHubSettingsClientModel, UserlistItemCollapsed = user.UserlistItemCollapsed, CreatedOn = user.CreatedOn, CreatedBy = user.CreatedBy, ModifiedOn = user.ModifiedOn, ModifiedBy = user.ModifiedBy }); }
private async Task <ChatHubUser> OnConnectedGuest() { string guestname = null; guestname = Context.GetHttpContext().Request.Query["guestname"]; guestname = guestname.Trim(); if (string.IsNullOrEmpty(guestname) || !this.IsValidGuestUsername(guestname)) { throw new HubException("No valid username."); } string username = this.CreateUsername(guestname); string displayname = this.CreateDisplaynameFromUsername(username); if (await this.chatHubRepository.GetUserByDisplayName(displayname) != null) { throw new HubException("Displayname already in use. Goodbye."); } string email = "*****@*****.**"; string password = "******"; ChatHubUser chatHubUser = new ChatHubUser() { SiteId = 1, Username = username, DisplayName = displayname, Email = email, LastIPAddress = Context.GetHttpContext().Connection.RemoteIpAddress.ToString(), }; chatHubUser = this.chatHubRepository.AddChatHubUser(chatHubUser); if (chatHubUser != null && chatHubUser.Username != RoleNames.Host) { List <Role> roles = this.roles.GetRoles(chatHubUser.SiteId).Where(item => item.IsAutoAssigned).ToList(); foreach (Role role in roles) { UserRole userrole = new UserRole(); userrole.UserId = chatHubUser.UserId; userrole.RoleId = role.RoleId; userrole.EffectiveDate = null; userrole.ExpiryDate = null; userRoles.AddUserRole(userrole); } } ChatHubConnection ChatHubConnection = new ChatHubConnection() { ChatHubUserId = chatHubUser.UserId, ConnectionId = Context.ConnectionId, IpAddress = Context.GetHttpContext().Connection.RemoteIpAddress.ToString(), UserAgent = Context.GetHttpContext().Request.Headers["User-Agent"].ToString(), Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Active) }; ChatHubConnection = this.chatHubRepository.AddChatHubConnection(ChatHubConnection); ChatHubSettings ChatHubSetting = new ChatHubSettings() { UsernameColor = "#7744aa", MessageColor = "#44aa77", ChatHubUserId = chatHubUser.UserId }; ChatHubSetting = this.chatHubRepository.AddChatHubSetting(ChatHubSetting); return(chatHubUser); }