예제 #1
0
        public void AddPrivateMessage([FromBody] PrivateMessage privateMessage, [FromUri] int chatId)
        {
            var chat           = chatRepository.GetById(chatId);
            var messagesInChat = chat.Messages;

            privateMessageRepository.Add(privateMessage);
            privateMessageRepository.SaveChanges(privateMessage);
            messagesInChat.Add(privateMessage);
            dataContext.SaveChanges();
        }
예제 #2
0
 public async void CreatePrivateMessageAsync(PrivateMessage privateMessage)
 {
     using (PrivateMessageRepository db = GetUnit().PrivateMessage)
     {
         await Task.Run(
             () =>
         {
             db.Add(privateMessage);
             db.Save();
         });
     }
 }
예제 #3
0
        public ActionResult Publish(PrivateMessage model)
        {
            var    flag = TryUpdateModel <PrivateMessage>(model, new string[] { "Name", "Email", "Content" });
            string msg  = string.Empty;

            if (flag)
            {
                model.PublishDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                model.StatusId    = 1;
                privateMessageRepository.Add(model);
                msg = "发表成功";
            }
            else
            {
                msg = "发表失败";
            }
            return(Json(new { flag = flag, msg = msg }, JsonRequestBehavior.AllowGet));
        }