Exemplo n.º 1
0
        public Chatroom CreateChat(Chat_Create create)
        {
            Chatroom chat = new Chatroom();

            chat.chatroomID = create.chatroomID;
            List <string> members = create.Participants;

            chat.Participants = members;
            foreach (var id in members)
            {
                var user = _users.Find <User>(x => x.uID == id).FirstOrDefault();
                if (user == null)
                {
                    continue;
                }
                var filter = Builders <User> .Filter.Eq(x => x.uID, id);

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

                _users.UpdateOne(filter, update);
            }
            return(chat);

            //------------------------------------------------------------------------------
            //
            // Add notification to all the subscribers and members that initiate this method
            //
            //------------------------------------------------------------------------------
        }
Exemplo n.º 2
0
        public ActionResult <Chatroom> CreateChat([FromBody] Chat_Create create)
        {
            Chatroom chatroom = new Chatroom();

            chatroom = _ChatService.CreateChat(create);
            if (chatroom == null)
            {
                return(BadRequest());
            }
            return(Ok(chatroom));
        }