Exemple #1
0
        public void RemoveUserFromGroupChat(int chatId, string userId)
        {
            GroupChatUsers dbEntry = context.GroupChatUsers
                                     .FirstOrDefault(cu => cu.GroupChatId == chatId && cu.UserId == userId);

            if (dbEntry != null)
            {
                foreach (GroupChatMessage msg in context.GroupChatMessages.Where(m => m.GroupChatId == chatId))
                {
                    if (msg.UserId == dbEntry.UserId)
                    {
                        //delete message views
                        foreach (GroupMessageView view in context.GroupMessageViews.Where(v => v.MessageId == msg.MessageId))
                        {
                            context.GroupMessageViews.Remove(view);
                        }
                        context.GroupChatMessages.Remove(msg);
                    }
                    else
                    {
                        GroupMessageView view = context.GroupMessageViews.FirstOrDefault(v => v.MessageId == msg.MessageId &&
                                                                                         v.UserId == dbEntry.UserId);
                        if (view != null)
                        {
                            context.GroupMessageViews.Remove(view);
                        }
                    }
                }

                context.GroupChatUsers.Remove(dbEntry);
                context.SaveChanges();
            }
        }
Exemple #2
0
        public void AddUserToGroupChat(int chatId, string userId)
        {
            GroupChatUsers dbEntry = new GroupChatUsers
            {
                GroupChatId = chatId,
                UserId      = userId
            };

            dbEntry.CreatedAt = DateTime.Now;
            dbEntry.UpdatedAt = DateTime.Now;
            context.GroupChatUsers.Add(dbEntry);
            context.SaveChanges();
        }
Exemple #3
0
        public void GroupAddUserToChat(int chatId, int groupId)
        {
            foreach (GroupUsers gUser in context.GroupUsers.Where(g => g.GroupId == groupId))
            {
                GroupChatUsers dbEntry = new GroupChatUsers
                {
                    GroupChatId = chatId,
                    UserId      = gUser.AppUserId
                };

                dbEntry.CreatedAt = DateTime.Now;
                dbEntry.UpdatedAt = DateTime.Now;
                context.GroupChatUsers.Add(dbEntry);
            }
            context.SaveChanges();
        }