Ejemplo n.º 1
0
        public void sendmessage(int sid, int rid, string name, string rName, string msg)
        {
            Message m = new Message()
            {
                Msg       = msg,
                Name      = name,
                SenderId  = sid,
                ReceverId = rid,
                Date      = DateTime.Now,
                Status    = 0,
                Rname     = rName
            };

            db.Messages.Add(m);

            //save data


            List <Connection> c = db.Connections.Where(n => (n.UserId == rid && n.SendId == sid) || (n.UserId == rid && n.SendId == 0)).ToList();

            for (int i = 0; i < c.Count; i++)
            {
                Clients.Client(c[i].ConId).SendAsync("recive", name, msg, DateTime.Now.ToString());
            }
            c = db.Connections.Where(n => n.UserId == sid && n.SendId == rid).ToList();
            for (int i = 0; i < c.Count; i++)
            {
                Clients.Client(c[i].ConId).SendAsync("AllSend", name, msg, DateTime.Now.ToString());
            }
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        public void PostAsync(Chat chat)
        {
            if (ModelState.IsValid)
            {
                chat.UserId = int.Parse(User.FindFirst("UserId").Value);
                chat.Date   = DateTime.Now;
                _context.Add(chat);
                _context.SaveChanges();
            }

            return;
        }
Ejemplo n.º 3
0
        public IActionResult TodoView(Todo todo, int id, int delete)  
        {
            //IDが0なら登録処理
            if (id == 0)
            {
                if (todo.TodoContent == "")
                {
                    return(null);
                }

                todo.UserId  = int.Parse(User.FindFirst("UserId").Value);
                todo.AddDate = DateTime.Now;
                _context.Add(todo);
                _context.SaveChanges();

                return(ViewComponent("TodoView", todo.UserId));
            }

            //Deleteに値があれば削除処理
            if (delete != 0)
            {
                _context.Todo.Remove(_context.Todo.Where(m => m.TodoId == delete).FirstOrDefault());
                _context.SaveChanges();
                return(ViewComponent("TodoView", int.Parse(User.FindFirst("UserId").Value)));
            }

            //更新処理
            var tmp = _context.Todo.Where(m => m.TodoId == id).FirstOrDefault();

            if (tmp.Complete == true)
            {
                tmp.Complete = false;
            }
            else
            {
                tmp.Complete = true;
            }
            _context.SaveChanges();
            return(ViewComponent("TodoView", tmp.UserId));
        }