Пример #1
0
        public async Task <Chat_MemberInfo> AddMembers(Chat_AddMembers add)
        {
            List <string> members = new List <string>();

            members = add.Members;
            foreach (var member in members)
            {
                var filter = Builders <User> .Filter.Eq(x => x.uID, add.uID);

                var update = Builders <User> .Update.AddToSet(x => x.Chatrooms, add.chatroomID);

                _users.UpdateOne(filter, update);
            }

            Chatroom chat = new Chatroom();

            chat = _chatrooms.Find <Chatroom>(x => x.chatroomID == add.chatroomID).FirstOrDefault();
            var filter_chat = Builders <Chatroom> .Filter.Eq(x => x.chatroomID, add.chatroomID);

            var update_chat = Builders <Chatroom> .Update.AddToSet(x => x.Participants, add.uID);

            var status = await _chatrooms.UpdateOneAsync(filter_chat, update_chat);


            Chat_MemberInfo info = new Chat_MemberInfo();

            info = GetMembersInfo_Single(add.chatroomID);
            return(info);
        }
Пример #2
0
        public ActionResult <Chatroom> GetMemberInfo([FromBody] StringClass model)
        {
            Chat_MemberInfo memberInfo = new Chat_MemberInfo();

            memberInfo = _ChatService.GetMembersInfo_Single(model.str);
            if (memberInfo == null)
            {
                return(BadRequest());
            }
            return(Ok(memberInfo));
        }
Пример #3
0
        public async Task <ActionResult <Chatroom> > AddMember([FromBody] Chat_AddMembers add)
        {
            Chat_MemberInfo chatroom = new Chat_MemberInfo();

            Task <Chat_MemberInfo> task = _ChatService.AddMembers(add);

            chatroom = await task;

            if (chatroom == null)
            {
                return(BadRequest());
            }
            return(Ok(chatroom));
        }
Пример #4
0
        public List <Chat_MemberInfo> GetMembersInfo_All(List <string> chatroomIDs)
        {
            List <Chat_MemberInfo> list = new List <Chat_MemberInfo>();

            foreach (var chatroomID in chatroomIDs)
            {
                Chat_MemberInfo info = new Chat_MemberInfo();
                info = GetMembersInfo_Single(chatroomID);
                if (info == null)
                {
                    continue;
                }
                list.Add(info);
            }
            return(list);
        }
Пример #5
0
        public Chat_MemberInfo GetMembersInfo_Single(string chatroomID)
        {
            Chatroom        chat = new Chatroom();
            Chat_MemberInfo list = new Chat_MemberInfo();

            chat = _chatrooms.Find <Chatroom>(x => x.chatroomID == chatroomID).FirstOrDefault();
            List <User_Personal> Infos = new List <User_Personal>();

            foreach (var id in chat.Participants)
            {
                var user = _users.Find <User>(x => x.uID == id).FirstOrDefault();
                if (user == null)
                {
                    continue;
                }
                Infos.Add(user.Personal);
            }
            list.MemberInfos = Infos;
            return(list);
        }