コード例 #1
0
ファイル: ChatHub.cs プロジェクト: sotillo257/Brokolee
        public void Connect(string userID)//string userName, string email
        {
            string userName = "", email = "";
            var    connectionId = Context.ConnectionId;
            long   uID          = Convert.ToInt64(userID);
            user   curUser      = entities.users.Find(uID);

            userName = curUser.first_name1 + " " + curUser.last_name1;
            email    = curUser.email;
            using (pjrdev_condominiosEntities dc = new pjrdev_condominiosEntities())
            {
                var item = dc.onlineusers.FirstOrDefault(x => x.user_id == uID);
                if (item != null)
                {
                    item.connectionID = connectionId;
                    item.updated_at   = DateTime.Now;
                    item.first_name   = curUser.first_name1;
                    item.last_name    = curUser.last_name1;
                    item.user_img     = null;
                    //curUser.user_img;
                    item.is_active = true;
                    item.is_online = true;
                    dc.SaveChanges();

                    // Disconnect
                    //Clients.All.onUserDisconnectedExisting(item.ConnectionId, item.UserName);

                    // send to caller
                    var connectedUsers = dc.onlineusers.Where(m => m.user_id != uID && m.is_online == true).ToList();
                    var CurrentMessage = dc.chatmessages.Where(m => m.from_user_id == uID || m.to_user_id == uID).ToList();
                    Clients.Caller.onConnected(connectionId, userName);
                }

                var users = dc.onlineusers.ToList();
                if (users.Where(x => x.user_id == uID).ToList().Count == 0)
                {
                    var userdetails = new onlineuser
                    {
                        connectionID = connectionId,
                        user_id      = uID,
                        is_online    = true,
                        is_active    = true,
                        created_at   = DateTime.Now,
                        updated_at   = DateTime.Now
                    };
                    dc.onlineusers.Add(userdetails);
                    dc.SaveChanges();

                    // send to caller
                    var connectedUsers = dc.onlineusers.Where(m => m.user_id != uID && m.is_online == true).ToList();
                    var CurrentMessage = dc.chatmessages.Where(m => m.from_user_id == uID || m.to_user_id == uID).ToList();
                    Clients.Caller.onConnected(connectionId, userName);
                }

                // send to all except caller client
                Clients.AllExcept(connectionId).onNewUserConnected(connectionId, userName, email);
            }
        }
コード例 #2
0
        public JsonResult GetSelUser(string userId)
        {
            //try
            //{
            int        imgtype = 1;
            int        online  = 1;
            string     imgpath = "user.svg";
            long       uID     = Convert.ToInt64(userId);
            onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();

            if (selUser.user_img != null)
            {
                imgpath = selUser.user_img;
                imgtype = 2;
            }

            if (selUser.is_online == false)
            {
                online = 0;
            }

            List <chatmessage> chatmessageList = new List <chatmessage>();
            long curId   = (long)Session["USER_ID"];
            user curUser = entities.users.Find(curId);

            chatmessageList = entities.chatmessages.Where(
                m => (m.from_user_id == curId && m.to_user_id == uID) ||
                (m.from_user_id == uID && m.to_user_id == curId)).ToList();

            selUserViewModel viewModel = new selUserViewModel();

            viewModel.chatmessageList = chatmessageList;
            viewModel.curUser         = curUser;
            viewModel.selUser         = selUser;
            string patialView = "~/Areas/webmaster/Views/comunicaciones/_chatbox.cshtml";
            string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);

            return(Json(new
            {
                result = "success",
                imgpath = imgpath,
                imgtype = imgtype,
                online = online,
                html = postsHtml,
                name = selUser.first_name + " " + selUser.last_name
            }));
            //    }
            //        catch (Exception ex)
            //        {
            //            return Json(new {
            //                result = "error",
            //                exception = ex.Message
            //});
            //        }
        }
コード例 #3
0
 public ActionResult privados()
 {
     if (Session["USER_ID"] != null)
     {
         try
         {
             long communityAct = Convert.ToInt64(Session["CURRENT_COMU"]);
             long userId       = (long)Session["USER_ID"];
             user curUser      = entities.users.Find(userId);
             List <ShowMessage> pubMessageList = ep.GetChatMessages(userId);
             List <onlineuser>  onlineUserList = entities.onlineusers
                                                 .Where(m => m.user_id != userId).ToList();
             comunicacionesViewModel viewmodel = new comunicacionesViewModel();
             titulosList                      = ep.GetTitulosByTitular(userId);
             listComunities                   = ep.GetCommunityListByTitular(titulosList);
             viewmodel.communityList          = listComunities;
             viewmodel.side_menu              = "comunicaciones";
             viewmodel.side_sub_menu          = "comunicaciones_privados";
             viewmodel.document_category_list = entities.document_type.Where(x => x.community_id == communityAct).ToList();
             viewmodel.curUser                = curUser;
             viewmodel.onlineUserList         = onlineUserList;
             if (onlineUserList.Count > 0)
             {
                 onlineuser selUser = onlineUserList.First();
                 viewmodel.selUser = selUser;
                 long selUserID = selUser.user_id;
                 viewmodel.chatmessageList = entities.chatmessages.Where(
                     m => (m.from_user_id == userId && m.to_user_id == selUserID) ||
                     (m.from_user_id == selUserID && m.to_user_id == userId)).ToList();
             }
             else
             {
                 viewmodel.selUser         = null;
                 viewmodel.chatmessageList = null;
             }
             viewmodel.pubTaskList    = ep.GetNotifiTaskList(userId);
             viewmodel.pubMessageList = pubMessageList;
             viewmodel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
             return(View(viewmodel));
         }
         catch (Exception ex)
         {
             return(Redirect(Url.Action("error", "control", new { Error = "Agregar comentario blog: ", ex.Message })));
         }
     }
     else
     {
         return(Redirect(ep.GetLogoutUrl()));
     }
 }
コード例 #4
0
        public JsonResult DeleteMessage(long selUserId, long messageId)
        {
            long uID   = selUserId;
            long curId = (long)Session["USER_ID"];
            List <chatmessage> chatmessageList = new List <chatmessage>();
            selUserViewModel   viewModel       = new selUserViewModel();

            try
            {
                chatmessage chatmessage = entities.chatmessages.Find(messageId);
                entities.chatmessages.Remove(chatmessage);
                entities.SaveChanges();
                user       curUser = entities.users.Find(curId);
                onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();
                chatmessageList = entities.chatmessages.Where(
                    m => (m.from_user_id == curId && m.to_user_id == uID) ||
                    (m.from_user_id == uID && m.to_user_id == curId)).ToList();
                viewModel.chatmessageList = chatmessageList;
                viewModel.curUser         = curUser;
                viewModel.selUser         = selUser;
                string patialView = "~/Areas/webmaster/Views/comunicaciones/_chatbox.cshtml";
                string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);
                return(Json(new
                {
                    result = "success",
                    html = postsHtml,
                }));
            }
            catch (Exception ex)
            {
                user       curUser = entities.users.Find(curId);
                onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();
                chatmessageList = entities.chatmessages.Where(
                    m => (m.from_user_id == curId && m.to_user_id == uID) ||
                    (m.from_user_id == uID && m.to_user_id == curId)).ToList();
                viewModel.chatmessageList = chatmessageList;
                viewModel.curUser         = curUser;
                viewModel.selUser         = selUser;
                string patialView = "~/Areas/webmaster/Views/comunicaciones/_chatbox.cshtml";
                string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);
                return(Json(new
                {
                    result = "error",
                    html = postsHtml,
                    exception = ex.Message
                }));
            }
        }
コード例 #5
0
        public void SaveUserOnlineStatus(onlineuser obj)
        {
            var query = entities.onlineusers.Where(m => m.user_id == obj.user_id &&
                                                   m.is_active == true && m.connectionID == obj.connectionID).FirstOrDefault();

            if (obj != null)
            {
                query.is_online    = obj.is_online;
                query.updated_at   = DateTime.Now;
                query.connectionID = obj.connectionID;
            }
            else
            {
                obj.created_at = DateTime.Now;
                obj.updated_at = DateTime.Now;
                obj.is_active  = true;
                entities.onlineusers.Add(obj);
            }
            entities.SaveChanges();
        }
コード例 #6
0
        public ActionResult privados()
        {
            if (Session["USER_ID"] != null)
            {
                long userId       = (long)Session["USER_ID"];
                long communityAct = Convert.ToInt64(Session["CURRENT_COMU"]);
                user curUser      = entities.users.Find(userId);
                List <ShowMessage> pubMessageList = ep.GetChatMessages(userId);
                List <onlineuser>  onlineUserList = entities.onlineusers
                                                    .Where(m => m.user_id != userId).ToList();
                privadosComViewModel viewModel = new privadosComViewModel();
                viewModel.side_menu     = "comunicaciones";
                viewModel.side_sub_menu = "comunicaciones_privados";

                viewModel.curUser        = curUser;
                viewModel.onlineUserList = onlineUserList;
                if (onlineUserList.Count > 0)
                {
                    onlineuser selUser = onlineUserList.First();
                    viewModel.selUser = selUser;
                    long selUserID = selUser.user_id;
                    viewModel.chatmessageList = entities.chatmessages.Where(
                        m => (m.from_user_id == userId && m.to_user_id == selUserID) ||
                        (m.from_user_id == selUserID && m.to_user_id == userId)).ToList();
                }
                else
                {
                    viewModel.selUser         = null;
                    viewModel.chatmessageList = null;
                }
                viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                viewModel.pubMessageList = pubMessageList;
                viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                return(View(viewModel));
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }
コード例 #7
0
ファイル: ChatHub.cs プロジェクト: sotillo257/Brokolee
 public override Task OnDisconnected(bool stopCalled)
 {
     using (pjrdev_condominiosEntities dc = new pjrdev_condominiosEntities())
     {
         string userName     = "";
         var    connectionID = Context.ConnectionId;
         var    item         = dc.onlineusers.FirstOrDefault(x => x.connectionID == connectionID);
         if (item != null)
         {
             long uID     = item.user_id;
             user curUser = entities.users.Find(uID);
             userName       = curUser.first_name1 + " " + curUser.last_name1;
             item.is_online = false;
             onlineuser onlineuserItem = dc.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();
             if (onlineuserItem != null)
             {
                 onlineuserItem.is_online    = false;
                 onlineuserItem.connectionID = connectionID;
                 onlineuserItem.updated_at   = DateTime.Now;
             }
             else
             {
                 onlineuserItem              = new onlineuser();
                 onlineuserItem.user_id      = uID;
                 onlineuserItem.connectionID = connectionID;
                 onlineuserItem.is_online    = false;
                 onlineuserItem.created_at   = DateTime.Now;
                 onlineuserItem.updated_at   = DateTime.Now;
                 dc.onlineusers.Add(onlineuserItem);
             }
             dc.SaveChanges();
             Clients.All.onUserDisconnected(connectionID, userName);
         }
     }
     return(base.OnDisconnected(stopCalled));
 }