Esempio n. 1
0
        public async Task UnignoreUser(string username)
        {
            ChatHubUser user = await this.GetChatHubUserAsync();

            ChatHubUser targetUser = await this.chatHubRepository.GetUserByUserNameAsync(username);

            if (user != null && targetUser != null)
            {
                ChatHubIgnore chatHubIgnore = this.chatHubRepository.GetChatHubIgnore(user.UserId, targetUser.UserId);

                if (chatHubIgnore != null)
                {
                    this.chatHubRepository.DeleteChatHubIgnore(chatHubIgnore);

                    var targetUserClientModel = this.chatHubService.CreateChatHubUserClientModel(targetUser);
                    foreach (var connection in user.Connections.Active())
                    {
                        await Clients.Client(connection.ConnectionId).SendAsync("RemoveIgnoredUser", targetUserClientModel);
                    }

                    var userClientModel = this.chatHubService.CreateChatHubUserClientModel(user);
                    foreach (var connection in targetUser.Connections.Active())
                    {
                        await Clients.Client(connection.ConnectionId).SendAsync("RemoveIgnoredByUser", userClientModel);
                    }
                }
            }
        }
Esempio n. 2
0
 public void DeleteChatHubIgnore(ChatHubIgnore chatHubIgnore)
 {
     try
     {
         db.ChatHubIgnore.Remove(chatHubIgnore);
         db.SaveChanges();
     }
     catch
     {
         throw;
     }
 }
Esempio n. 3
0
 public ChatHubIgnore UpdateChatHubIgnore(ChatHubIgnore chatHubIgnore)
 {
     try
     {
         db.Entry(chatHubIgnore).State = EntityState.Modified;
         db.SaveChanges();
         return(chatHubIgnore);
     }
     catch
     {
         throw;
     }
 }
Esempio n. 4
0
        public ChatHubIgnore AddChatHubIgnore(ChatHubIgnore chatHubIgnore)
        {
            try
            {
                db.ChatHubUser.Attach(chatHubIgnore.User);
                db.Entry(chatHubIgnore.User).State = EntityState.Modified;

                db.ChatHubIgnore.Add(chatHubIgnore);
                db.SaveChanges();
                return(chatHubIgnore);
            }
            catch
            {
                throw;
            }
        }
        public void IgnoreUser(ChatHubUser callerUser, ChatHubUser targetUser)
        {
            ChatHubIgnore chatHubIgnore = this.chatHubRepository.GetChatHubIgnore(callerUser.UserId, targetUser.UserId);

            if (chatHubIgnore != null)
            {
                chatHubIgnore.ModifiedOn = DateTime.Now;
                this.chatHubRepository.UpdateChatHubIgnore(chatHubIgnore);
            }
            else
            {
                chatHubIgnore = new ChatHubIgnore()
                {
                    ChatHubUserId        = callerUser.UserId,
                    ChatHubIgnoredUserId = targetUser.UserId,
                    User = callerUser
                };

                this.chatHubRepository.AddChatHubIgnore(chatHubIgnore);
            }
        }
        public void IgnoreUser(ChatHubUser callerUser, ChatHubUser targetUser)
        {
            ChatHubIgnore chatHubIgnore = null;
            var           users         = this.chatHubRepository.GetIgnoredUsers(targetUser);

            chatHubIgnore = users.Where(u => u.ChatHubUserId == targetUser.UserId).FirstOrDefault();

            if (chatHubIgnore != null)
            {
                chatHubIgnore.ModifiedOn = DateTime.Now;
                this.chatHubRepository.UpdateChatHubIgnore(chatHubIgnore);
            }
            else
            {
                chatHubIgnore = new ChatHubIgnore()
                {
                    ChatHubUserId        = callerUser.UserId,
                    ChatHubIgnoredUserId = targetUser.UserId,
                    User = callerUser
                };

                this.chatHubRepository.AddChatHubIgnore(chatHubIgnore);
            }
        }