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 async Task <ChatHubUser> IdentifyGuest(string connectionId) { ChatHubConnection connection = await Task.Run(() => chatHubRepository.GetConnectionByConnectionId(connectionId)); if (connection != null) { return(await this.chatHubRepository.GetUserByIdAsync(connection.User.UserId)); } return(null); }
public ChatHubConnection UpdateChatHubConnection(ChatHubConnection ChatHubConnection) { try { db.Entry(ChatHubConnection).State = EntityState.Modified; db.SaveChanges(); return(ChatHubConnection); } catch { throw; } }
public ChatHubConnection AddChatHubConnection(ChatHubConnection ChatHubConnection) { try { db.ChatHubConnection.Add(ChatHubConnection); db.SaveChanges(); return(ChatHubConnection); } catch { throw; } }
public ChatHubConnection CreateChatHubConnectionClientModel(ChatHubConnection connection) { return(new ChatHubConnection() { ChatHubUserId = connection.ChatHubUserId, Status = connection.Status, User = connection.User, CreatedOn = connection.CreatedOn, CreatedBy = connection.CreatedBy, ModifiedOn = connection.ModifiedOn, ModifiedBy = connection.ModifiedBy }); }
public void DeleteChatHubConnection(int ChatHubConnectionId, int ChatHubUserId) { try { ChatHubConnection ChatHubConnection = db.ChatHubConnection.Where(item => item.Id == ChatHubConnectionId) .Where(item => item.ChatHubUserId == ChatHubUserId).FirstOrDefault(); db.ChatHubConnection.Remove(ChatHubConnection); db.SaveChanges(); } catch { throw; } }
public ChatHubConnection CreateChatHubConnectionClientModel(ChatHubConnection connection) { return(new ChatHubConnection() { ChatHubUserId = connection.ChatHubUserId, ConnectionId = this.MakeStringAnonymous(connection.ConnectionId, 7, '*'), Status = connection.Status, User = connection.User, CreatedOn = connection.CreatedOn, CreatedBy = connection.CreatedBy, ModifiedOn = connection.ModifiedOn, ModifiedBy = connection.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); }