public int Add(string msg, int playtime, int couid, int olid) { if (string.IsNullOrWhiteSpace(msg)) { return(0); } if (msg.Trim() == "") { return(0); } Song.Entities.Accounts acc = Extend.LoginState.Accounts.CurrentUser; if (acc == null) { return(0); } Song.Entities.Message entity = new Entities.Message(); entity.Msg_Context = msg.Length > 200 ? msg.Substring(0, 200) : msg; entity.Msg_PlayTime = playtime; entity.Cou_ID = couid; entity.Ol_ID = olid; entity.Ac_ID = acc.Ac_ID; entity.Ac_AccName = acc.Ac_AccName; entity.Ac_Name = acc.Ac_Name; entity.Msg_Phone = string.IsNullOrWhiteSpace(acc.Ac_MobiTel1) ? acc.Ac_MobiTel2 : acc.Ac_MobiTel1; entity.Msg_QQ = acc.Ac_Qq; entity.Ac_Photo = acc.Ac_Photo; entity.Msg_IP = WeiSha.Common.Browser.IP; return(Business.Do <IMessage>().Add(entity)); }
public ActionResult DeleteMessage(int msgID) { Entities.Message dltMessage = new Entities.Message(); dltMessage = _messageService.GetByMessageId(msgID); _messageService.Delete(dltMessage); return(PartialView("SendMessage", _messageService.GetAllLazyWithoutID().OrderBy(x => x.InsertDate).ToList())); }
/// <summary> /// Sends an email. /// </summary> public async Task SendMessage(Entities.Message message) { Console.Write("Sending message..."); await Task.Delay(1000); Console.WriteLine($"To: {message.Email}\nBody: {message.Body}"); }
private void btnRead_Click(object sender, EventArgs e) { MessageBus messageBus = new MessageBus(); int result = messageBus.validateMessage(txtRoomId.Text, txtUserId.Text); if (result == 0) { Entities.Message message = new Entities.Message(); message.roomId = Int32.Parse(txtRoomId.Text); message.UserId = Int32.Parse(txtUserId.Text); DataTable dt = messageBus.read(message); if (dt != null) { foreach (DataRow row in dt.Rows) { string msg = ""; int cont = 0; foreach (DataColumn column in dt.Columns) { if (cont == 0) { msg += row[column].ToString() + ": "; cont++; } else { msg += row[column].ToString() + ""; cont++; } } rtxtChat.Text += msg + System.Environment.NewLine; } } else { MessageBox.Show("No se pudo cargar los mensajes"); } } else if (result == 1) { MessageBox.Show("Por favor ingrese un número de room valido"); } else if (result == 2) { MessageBox.Show("Por favor ingrese un ID valido"); } else { MessageBox.Show("Se ha presentado un error en el sistema"); } }
public async Task <IActionResult> SendMessage([FromBody] Entities.Message sentMessage) { try { var Receiver = await _db.Users.FindAsync(sentMessage.ReceiverId); var Sender = await _db.Users.FindAsync(sentMessage.SenderId); var AmIBlocked = await _db.BlockedUsers.FirstOrDefaultAsync(x => !x.IsDeleted && x.UserId == Receiver.Id && x.BlockedUserId == Sender.Id); if (AmIBlocked != null) { return(BadRequest("You cant send a message to " + Receiver.Name + " since you are blocked.")); } if (sentMessage != null) { _db.Message.Add(sentMessage); await _db.SaveChangesAsync(); await Task.Run(async() => { FCMClient client = new FCMClient(ServerApiKey); //as derived from https://console.firebase.google.com/project/ var message = new FirebaseNet.Messaging.Message() { To = Receiver.FireBaseToken, //topic example /topics/all Notification = new IOSNotification() { Body = sentMessage.Text, Title = Sender.Name, }, Data = new Dictionary <string, string> { { "Body", sentMessage.Text }, { "Title", "New Message" }, { "SenderId", sentMessage.SenderId }, { "SenderPicture", Sender?.ProfilePicUrl } } }; var result = await client.SendMessageAsync(message); }); return(Ok()); } return(BadRequest()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
/// <summary> /// Determines whether <see cref="Entities.Message"/> is suitable for current criteria /// <para/> /// Is subject name the same /// </summary> /// <param name="message"> /// An instance of <see cref="Entities.Message"/> to check /// </param> /// <param name="subjectName"> /// A subject name that <see cref="Entities.Message"/> should have to pass criterion /// </param> /// <returns> /// True if <see cref="Entities.Message"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throwns when <paramref name="message"/> or <paramref name="subjectName"/> is null; /// </exception> public static bool Where(Entities.Message message, string subjectName) { if (message == null) { throw new System.ArgumentNullException(nameof(message)); } if (subjectName == null) { throw new System.ArgumentNullException(nameof(subjectName)); } return(message.Subject.Name == subjectName); }
public async void Post([FromBody] Entities.Message value) { string id = null; foreach (var claim in (User.Identity as ClaimsIdentity).Claims) { if (claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier") { id = claim.Value; } } Hub.Clients.Group(id).TestNotification(value.Title, value.Text); }
public ActionResult SendMessage(int senderID, string textMessage) { if (textMessage != "") { Entities.Message messages = new Entities.Message { UserID = senderID, Text = textMessage.ToString(), InsertDate = DateTime.Now }; _messageService.Add(messages); } return(PartialView(_messageService.GetAllLazyWithoutID().OrderBy(x => x.InsertDate).ToList())); }
/// <summary> /// Adds and displays the given message. /// When a new message is detected, this method should be called. /// </summary> /// <param name="message">the new message to add</param> public void OnNewMessage(Entities.Message message) { if (InvokeRequired) { Invoke(new Action(() => { OnNewMessage(message); })); return; } MessageRow mr = new MessageRow(message, this.channel, this); if (this.messages.Any()) { mr.Top = this.messages.Last().Top + this.messages.Last().Height; } else { mr.Top = 0; } this.messages.Add(mr); this.Controls.Add(mr); }
/// <summary> /// Determines whether <see cref="Entities.Message"/> is suitable for current criteria /// <para/> /// Is date in range /// </summary> /// <param name="message"> /// An instance of <see cref="Entities.Message"/> to check /// </param> /// <param name="from"> /// A minimum value for <see cref="Entities.Message.Date"/> /// </param> /// <param name="to"> /// A maximum value for <see cref="Entities.Message.Date"/> /// </param> /// <returns> /// True if <see cref="Entities.Message"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throwns when <paramref name="message"/> is null; /// </exception> public static bool Where(Entities.Message message, System.DateTime?from, System.DateTime?to) { if (message == null) { throw new System.ArgumentNullException(nameof(message)); } bool pass = true; if (from != null) { pass &= message.Date > from.Value; } if (to != null) { pass &= message.Date < to.Value; } return(pass); }
public List <Entities.Message> GetMessagesByTopic(int topicID, DateTime startDate) { List <Entities.Message> listMessages = new List <Entities.Message>(); try { using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["LoginDb"].ConnectionString)) { SqlCommand cmd = new SqlCommand("GetMessagesbyTopAndDate", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@topicID", topicID); cmd.Parameters.AddWithValue("@data", startDate); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Entities.Message mess = new Entities.Message( Convert.ToInt32(reader["ID"]), Convert.ToInt32(reader["TopicID"]), reader["TopicName"].ToString(), Convert.ToInt32(reader["UserID"]), reader["UserLogin"].ToString(), (DateTime)reader["AddDate"], reader["Text"].ToString() ); listMessages.Add(mess); } } } catch (Exception e) { ErrorDAL.AddNewError(DateTime.Now, e.ToString(), ""); throw new Exception("Oшибка данных"); } return(listMessages); }
private void btnSendMsg_Click(object sender, EventArgs e) { MessageBus messageBus = new MessageBus(); /* * Custom Message Error * return 1 - roomId * return 2 - userId * return 0 - okay */ int result = messageBus.validateMessage(txtRoomId.Text, txtUserId.Text); if (result == 0) { Entities.Message message = new Entities.Message(); message.Send = DateTime.Today; message.Text = txtSendMessage.Text; message.roomId = Int32.Parse(txtRoomId.Text); message.UserId = Int32.Parse(txtUserId.Text); if (messageBus.create(message)) { MessageBox.Show("Mensaje Enviado"); } else { MessageBox.Show("El mensaje no se pudo enviar"); } } else if (result == 1) { MessageBox.Show("Por favor ingrese un número de room valido"); } else if (result == 2) { MessageBox.Show("Por favor ingrese un ID valido"); } }
///// <summary> ///// 添加留言 ///// </summary> ///// <returns></returns> //[Student] //public int Add(string msg, int playtime, int couid, int olid) //{ // if (string.IsNullOrWhiteSpace(msg)) return 0; // if (msg.Trim() == "") return 0; // Song.Entities.Accounts acc = Extend.LoginState.Accounts.CurrentUser; // if (acc == null) return 0; // return this.Add(acc.Ac_AccName, playtime, couid, olid); //} /// <summary> /// 添加留言 /// </summary> /// <param name="acc">学员账号,如果账号为空则默认为当前登录账号</param> /// <param name="msg">留言信息</param> /// <param name="playtime">视频播放时间</param> /// <param name="couid">课程id</param> /// <param name="olid">章节id</param> /// <returns></returns> public int Add(string acc, string msg, int playtime, int couid, int olid) { Song.Entities.Accounts account = null; if (!string.IsNullOrWhiteSpace(acc)) { account = Business.Do <IAccounts>().AccountsSingle(acc, -1); } else { account = Extend.LoginState.Accounts.CurrentUser; } if (account == null) { throw new Exception("当前账号不存在"); } Song.Entities.Message entity = new Entities.Message(); entity.Msg_Context = msg.Length > 200 ? msg.Substring(0, 200) : msg; entity.Msg_PlayTime = playtime; if (couid <= 0) { Song.Entities.Outline outline = Business.Do <IOutline>().OutlineSingle(olid); if (outline != null) { couid = outline.Cou_ID; } } entity.Cou_ID = couid; entity.Ol_ID = olid; entity.Ac_ID = account.Ac_ID; entity.Ac_AccName = account.Ac_AccName; entity.Ac_Name = account.Ac_Name; entity.Msg_Phone = string.IsNullOrWhiteSpace(account.Ac_MobiTel1) ? account.Ac_MobiTel2 : account.Ac_MobiTel1; entity.Msg_QQ = account.Ac_Qq; entity.Ac_Photo = account.Ac_Photo; entity.Msg_IP = WeiSha.Common.Browser.IP; return(Business.Do <IMessage>().Add(entity)); }
public void Update(Entities.Message message, string username) { }
public MessageEventArgs(Message message) { Message = message; }
public static MessageMappingFactory MapTo(this Entities.Message message) { return(new MessageMappingFactory(message)); }
public List<Entities.Message> GetLastMessage(int topicID) { List<Entities.Message> listMessages = new List<Entities.Message>(); try { using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["LoginDb"].ConnectionString)) { SqlCommand cmd = new SqlCommand("GetLastMess", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@topicID", topicID); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Entities.Message mess = new Entities.Message( Convert.ToInt32(reader["ID"]), Convert.ToInt32(reader["TopicID"]), reader["TopicName"].ToString(), Convert.ToInt32(reader["UserID"]), reader["UserLogin"].ToString(), (DateTime)reader["AddDate"], reader["Text"].ToString() ); listMessages.Add(mess); } } } catch (Exception e) { ErrorDAL.AddNewError(DateTime.Now, e.ToString(), ""); throw new Exception("Oшибка данных"); } return listMessages; }
public MessageRow(Entities.Message message, Entities.Channel channel, Panel parent) { this.message = message; this.parent = parent; this.ismine = (Form1.Instance.user != null && message.UserId == Form1.Instance.user?.UserId); Color message_bg_color = Constants.BLUE; Color message_text_color = Constants.DARK_GRAY; if (this.ismine) { message_bg_color = Constants.LIGHT_PURPLE; message_text_color = Constants.LIGHT_GRAY; } this.image = new PictureBox(); this.textPane = new Panel(); this.text = new Label(); this.timestampLabel = new Label(); this.Width = this.parent.Width; this.image.Size = Constants.MEDIUM_IMAGE_SIZE; this.image.Left = Constants.MARGIN_SMALL.Left; this.image.Top = Constants.MARGIN_SMALL.Top; this.image.BackColor = Color.Crimson; this.image.SizeMode = PictureBoxSizeMode.Zoom; Entities.User usr = channel.Memberships.Where(m => m.UserDetails.UserId == message.UserId).First().UserDetails; if (!string.IsNullOrEmpty(usr.ProfilePicture)) { this.image.LoadAsync(usr.ProfilePicture); } else { this.image.Image = Properties.Resources.default_user_image; } this.textPane.Left = this.image.Left + this.image.Width + Constants.MARGIN_SMALL.Right; this.textPane.Top = Constants.MARGIN_SMALL.Top; this.textPane.MaximumSize = new Size((int)(0.8f * this.Width), int.MaxValue); this.textPane.BackColor = message_bg_color; this.textPane.BackgroundImage = Constants.TRANSPARENT_GRADIENT_VERTICAL; this.textPane.BackgroundImageLayout = ImageLayout.Stretch; this.textPane.AutoSize = true; this.text.Left = Constants.MARGIN_SMALL.Left; this.text.Top = Constants.MARGIN_SMALL.Top; this.text.MaximumSize = new Size(Constants.MAX_MESSAGE_PANE_WIDTH - Constants.MARGIN_SMALL.Left - Constants.MARGIN_SMALL.Right, int.MaxValue); this.text.Text = this.message.Contents; this.text.AutoSize = true; this.text.ForeColor = message_text_color; this.textPane.Height = Constants.MARGIN_SMALL.Top + this.text.Height + Constants.MARGIN_SMALL.Bottom; this.textPane.Width = Constants.MARGIN_SMALL.Left + this.text.Width + Constants.MARGIN_SMALL.Right; this.textPane.Controls.Add(this.text); this.textPane.AutoSize = true; if (this.textPane.Height < this.image.Height) { this.Height = this.image.Height + Constants.MARGIN_SMALL.Top + Constants.MARGIN_SMALL.Bottom; this.textPane.Top = this.image.Top + this.image.Height - this.textPane.Height; } else { this.Height = this.textPane.Height + Constants.MARGIN_SMALL.Top + Constants.MARGIN_SMALL.Bottom; this.image.Top = this.textPane.Top + this.textPane.Height - this.image.Height; } this.timestampLabel.Text = this.message.SentDate.ToString() + " " + this.message.UserId; this.timestampLabel.Left = this.Width - this.timestampLabel.Width - Constants.MARGIN_SMALL.Right; this.timestampLabel.Top = this.Height - this.timestampLabel.Height; this.timestampLabel.ForeColor = Constants.DARK_GRAY; if (this.ismine) { this.image.Left = this.timestampLabel.Left - Constants.MARGIN_SMALL.Left - this.image.Width - Constants.MARGIN_SMALL.Right; this.textPane.Left = this.image.Left - (Constants.MARGIN_SMALL.Left + this.textPane.Controls[0].Width + this.textPane.Controls[0].Left + Constants.MARGIN_SMALL.Right); } this.Controls.Add(this.image); this.Controls.Add(this.textPane); this.Controls.Add(this.timestampLabel); }
public static Models.Message ToModel(this Entities.Message entity) { return(mapper.Map <Models.Message>(entity)); }
/// <summary> /// Obtain the message content from the response object /// </summary> /// <param name="response">the response object</param> /// <returns>the Entities.Message object</returns> private static Entities.Message getMessageFromResponse(HttpResponseMessage response) { Entities.Message m = new Entities.Message(); // read the xml Stream content = response.Content.ReadAsStreamAsync().Result; content.Seek(0, SeekOrigin.Begin); m.LoadBinary(content); return m; }
public void Create(string _author, string toUsername, string text) { DateTime dateTimeNow = DateTime.Now; Entities.Message message = new Entities.Message(); MessageRom messageRom = null; var author = _context.Users.FirstOrDefault(x => x.Username == _author); var recipient = _context.Users.FirstOrDefault(x => x.Username == toUsername); var mesanduser = _context.MessageRomsAndUsers.Where(x => x.UserId == author.Id); foreach (var item in mesanduser) { var temp = _context.MessageRomsAndUsers.FirstOrDefault(x => x.UserId == recipient.Id && x.MessageRomId == item.MessageRomId); if (temp != null) { messageRom = _context.MessageRoms.FirstOrDefault(x => x.id == temp.MessageRomId); temp.MessageRom.LastMessageText = text; temp.MessageRom.TimeLastMessage = dateTimeNow; break; } } if (messageRom != null) { message.MessageRom = messageRom; message.MessageRomId = messageRom.id; message.Text = text; message.TimePost = dateTimeNow; message.authorId = author.Id; message.recipientid = recipient.Id; messageRom.Messages.Add(_context.Messages.Add(message).Entity); messageRom.TimeLastMessage = dateTimeNow; messageRom.LastMessageText = text; _context.SaveChanges(); } else { var mesrom = _context.MessageRoms.Add(new MessageRom() { Name = "", LastMessageText = text, TimeLastMessage = dateTimeNow }); _context.SaveChanges(); var mesromanduser = _context.MessageRomsAndUsers.Add(new MessageRomAndUser() { MessageRom = mesrom.Entity, MessageRomId = mesrom.Entity.id, User = author, UserId = author.Id }); var mesromanduser1 = _context.MessageRomsAndUsers.Add(new MessageRomAndUser() { MessageRom = mesrom.Entity, MessageRomId = mesrom.Entity.id, User = recipient, UserId = recipient.Id }); _context.SaveChanges(); mesrom.Entity.MessageRomAndUsers.Add(mesromanduser.Entity); mesrom.Entity.MessageRomAndUsers.Add(mesromanduser1.Entity); _context.SaveChanges(); message.MessageRom = mesrom.Entity; message.MessageRomId = mesrom.Entity.id; message.Text = text; message.TimePost = dateTimeNow; message.authorId = author.Id; message.recipientid = recipient.Id; mesrom.Entity.Messages.Add(_context.Messages.Add(message).Entity); var ff = ChatWebSocketMiddleware.GetSocketByUsername(recipient.Username); string messagee = JsonConvert.SerializeObject( new MessageRomDto() { id = mesrom.Entity.id, LastMessageText = mesrom.Entity.LastMessageText, Name = "", TimeLastMessage = mesrom.Entity.TimeLastMessage, Users = new List <UserDto>() { new UserDto() { CurrentImage = MessageService.GetImgUrlBy(ImageController.hoststring, author.CurrentImage, author.Username), FirstName = author.FirstName, Username = author.Username, Id = author.Id, IsFriend = true.ToString(), LastName = author.LastName, IsSendProposition = false.ToString() } } }); ChatWebSocketMiddleware.SendStringAsync(ff.Websocket, new Helpers.Message() { author = _author, recipient = recipient.Username, type = Helpers.MessagesType.RomCreate.Value, message = messagee }.ToString(), ff.cancellationToken); _context.SaveChanges(); } }