Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //redirect to the main page
            if (clsSmallItemsHandler.SessionIdIsSet == false)
            {
                Response.Redirect("/");
            }
            //end


            var          session   = HttpContext.Current.Session["user_id"];
            clsGroupChat groupChat = new clsGroupChat(session);//public chat



            //if send a message
            if (Request.Params["user_id"] != null)
            {
                var name      = Request.Params["user_name"];
                var user_id   = Request.Params["user_id"];
                var course_id = Request.Params["course_id"];
                var time      = Request.Params["time"].ToString().Replace("_", " ");
                var message   = Request.Params["message"];

                groupChat.InsertMessage(name, user_id, course_id, time, message);
            }



            //load all the chat to this page
            course_list = groupChat.CURRENT_USER_All_COURSE_ID_AND_NAME();
            user_id     = HttpContext.Current.Session["user_id"];
            user_name   = HttpContext.Current.Session["user_name"];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //redirect to the main page
            if (clsSmallItemsHandler.SessionIdIsSet == false)
            {
                Response.Redirect("/");
            }
            //end

            var          session   = HttpContext.Current.Session["user_id"];
            clsGroupChat groupChat = new clsGroupChat(session);       ///group chat

            clsPrivateChat privateChat = new clsPrivateChat(session); //private


            var javaScriptSerializer = new JavaScriptSerializer();

            var course_id       = Request.Params["course_id"];
            var messageLimit    = Request.Params["limit"];
            var current_chat_id = Request.Params["current_chat_id"];

            var token = Request.Params["token"];


            if (Request.Params["reset_group_notification"] != null)
            {
                groupChat.resetNotification(course_id);
            }

            else if (Request.Params["get_group_notification"] != null)
            {
                var notification = groupChat.current_user_Notification(course_id);
                //OBJECT -> JSON
                string myObjectJson = javaScriptSerializer.Serialize(notification);
                //return JSON
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(myObjectJson);
                Response.End();
            }
            else if (token == "get_group_messages")
            {
                var messages = groupChat.FetchMesssges(course_id, messageLimit);
                //OBJECT -> JSON
                string myObjectJson = javaScriptSerializer.Serialize(messages);
                //return JSON
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(myObjectJson);
                Response.End();
            }
            else if (Request.Params["reset_group_notification"] != null)
            {
                privateChat.resetNotification(course_id);
            }

            else if (Request.Params["get_private_notification"] != null)
            {
                var notification = privateChat.Current_user_Notification(course_id);
                //OBJECT -> JSON
                string myObjectJson = javaScriptSerializer.Serialize(notification);
                //return JSON
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(myObjectJson);
                Response.End();
            }
            else if (token == "get_private_messages")
            {
                var messages = privateChat.FetchMesssges(course_id, messageLimit, current_chat_id);
                //OBJECT -> JSON
                string myObjectJson = javaScriptSerializer.Serialize(messages);
                //return JSON
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(myObjectJson);
                Response.End();
            }
        }