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(); }
public async void CreatePrivateMessageAsync(PrivateMessage privateMessage) { using (PrivateMessageRepository db = GetUnit().PrivateMessage) { await Task.Run( () => { db.Add(privateMessage); db.Save(); }); } }
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)); }