예제 #1
0
        public async Task <Response <List <ShortChat> > > GetChatForMobileApp(int userId, int communityID)
        {
            List <ShortChat> chatTo   = new List <ShortChat>();
            List <ShortChat> chatFrom = new List <ShortChat>();
            //List<Chat> chat = new List<Chat>();
            List <ShortChat>             shortchatList = new List <ShortChat>();
            Response <List <ShortChat> > chatResponse  = new Response <List <ShortChat> >();

            if (UserExists(userId))
            {
                chatTo = (from l in db.Chats
                          where l.to == userId && l.communityID == communityID
                          select new ShortChat()
                {
                    chat = l,
                    fromName = l.userFrom.firstName,
                    toName = l.userTo.firstName,
                    IsMe = false,
                    adminID = l.@from
                }).ToList();
                chatFrom = (from l in db.Chats
                            where l.@from == userId && l.communityID == communityID
                            select new ShortChat()
                {
                    chat = l,
                    fromName = l.userFrom.firstName,
                    toName = l.userTo.firstName,
                    IsMe = true,
                    adminID = l.to
                }).ToList();

                //adding chatTo in chat
                shortchatList.AddRange(chatTo);
                //adding chatFrom in chat
                shortchatList.AddRange(chatFrom);
                ChatsController chatController = new ChatsController();
                //set Message isRead=true where userID is not from.(from=Admin UserID)


                shortchatList       = shortchatList.OrderBy(x => x.chat.chatMessageID).ToList();
                chatResponse.status = "Success";
                chatResponse.model  = shortchatList;
                return(chatResponse);
            }
            else
            {
                chatResponse.status = "Failed: User does not exists";
                chatResponse.model  = null;
                return(chatResponse);
            }
        }
예제 #2
0
        public async Task <Response <Chat> > GetChatUserbyMessageIDAndReadMessage(int messageID, string status)
        {
            Response <Chat> chatResponse   = new Response <Chat>();
            Chat            chat           = new Chat();
            List <Chat>     chatTo         = new List <Chat>();
            ChatsController chatController = new ChatsController();

            chat = (from l in db.Chats
                    where l.chatMessageID == messageID
                    select l).FirstOrDefault();
            int userID      = chat.to;
            int CommunityID = chat.communityID;

            if (chat == null)
            {
                chatResponse.status = "Failed: Message did not Found";
                chatResponse.model  = null;
                return(chatResponse);
            }
            else
            {
                if (status == "Read")
                {
                    chatTo = (from l in db.Chats
                              where l.to == userID && l.communityID == CommunityID
                              select l).ToList();
                    foreach (var item in chatTo)
                    {
                        if (item.isRead != true)
                        {
                            item.isRead = true;
                            await chatController.PutChat(item.chatMessageID, item);
                        }
                    }
                }
                else
                {
                    chat.isRead = false;
                    await chatController.PutChat(chat.chatMessageID, chat);
                }
                chatResponse.status = "Success";
                chatResponse.model  = chat;
                return(chatResponse);
            }
        }
예제 #3
0
        public async Task <Response <List <Chat> > > GetLatestChatForAdmin(int userIdTo, int AdminUserID, int communityID, int messageID)
        {
            List <Chat>             chatTo       = new List <Chat>();
            List <Chat>             chatFrom     = new List <Chat>();
            List <Chat>             chat         = new List <Chat>();
            Response <List <Chat> > chatResponse = new Response <List <Chat> >();

            if (UserExists(userIdTo) && UserExists(AdminUserID))
            {
                //chatTo = (from l in db.Chats
                //          where l.to == userIdTo && l.@from == AdminUserID && l.communityID == communityID && l.chatMessageID>messageID
                //          select l).Include(x => x.userFrom).ToList();
                chatFrom = (from l in db.Chats
                            where l.to == AdminUserID && l.@from == userIdTo && l.communityID == communityID && l.chatMessageID > messageID
                            select l).Include(x => x.userFrom).ToList();

                //adding chatTo in chat    '


                //chat.AddRange(chatTo);
                //adding chatFrom in chat
                chat.AddRange(chatFrom);
                ChatsController chatController = new ChatsController();
                //set Message isRead=true where adminUserID is not from.(from=UserID)
                //foreach (var item in chatTo)
                //{
                //    if (item.isRead != true)
                //    {
                //        await chatController.PutChat(item.chatMessageID, item);
                //    }

                //}
                chat = chat.OrderBy(x => x.chatMessageID).ToList();
                chatResponse.status = "Success";
                chatResponse.model  = chat;
                return(chatResponse);
            }
            else
            {
                chatResponse.status = "Failed: userIdTo or userIdFrom does not exists";
                chatResponse.model  = null;
                return(chatResponse);
            }
        }