Beispiel #1
0
        public void Send(string chat_id, string speaker, string from, string to, string message)
        {
            // Call the addNewMessageToPage method to update clients.
            //Clients.User(name).Send(message);
            chatEntities db = new chatEntities();
            chat_table   c  = new chat_table()
            {
                id        = GetHashString(chat_id),
                char_text = message,
                time      = DateTime.Now,
                speaker   = from
            };

            db.chat_table.Add(c);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
            }
            var user_list = chat_id.Split(',');

            foreach (var u in user_list)
            {
                if (u.Length == 0)
                {
                    continue;
                }
                Clients.User(u).addNewMessageToPage(speaker, message);
            }
        }
        public string Post([FromBody] dynamic value)
        {
            chatEntities db       = new chatEntities();
            string       username = value["username"];

            if ((from u in db.user_table where u.username == username select u).Count() != 0)
            {
                return("用户名已存在");
            }
            user_table usrModel = new user_table()
            {
                id        = Guid.NewGuid().ToString(),
                username  = value["username"],
                password  = value["password"],
                privilege = 1,
                sex       = value["sex"],
                age       = value["age"],
                info      = value["info"]
            };

            db.user_table.Add(usrModel);
            int resCount = db.SaveChanges();

            return(usrModel.id);
        }
Beispiel #3
0
 void updateState()
 {
     if (!(Session["login"] is null))
     {
         string       id   = Session["id"].ToString();
         chatEntities db   = new chatEntities();
         var          user = from u in db.user_table
                             where (u.id == id)
                             select u;
         user.First().last_app = DateTime.Now;
         db.SaveChanges();
     }
 }
        public string Post([FromBody] dynamic value)
        {
            if ((int)value["type"] == 1)
            {
                chatEntities db   = new chatEntities();
                string       id   = value["id"];
                var          list = from u in db.user_table where u.id == id select u;

                if ((list.Count() == 0))
                {
                    return("用户名不存在");
                }
                var user = list.First();
                user.password  = value["password"];
                user.privilege = value["privilege"];
                user.sex       = value["sex"];
                user.age       = value["age"];
                user.info      = value["info"];
                int resCount = db.SaveChanges();
                return(user.id);
            }
            else
            {
                chatEntities db       = new chatEntities();
                string       username = value["username"];
                var          list     = from u in db.user_table where u.username == username select u;

                if ((list.Count() == 0))
                {
                    return("用户名不存在");
                }
                var user = list.First();
                user.password = value["password"];
                user.sex      = value["sex"];
                user.age      = value["age"];
                user.info     = value["info"];
                int resCount = db.SaveChanges();
                return(user.id);
            }
        }