public static bool CreateMessage(DBO.Message message) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Message newMessage = new T_Message() { content = message.Content, date = message.Date, id_receiver = message.IdReceiver, id_sender = message.IdSender, isSeen = message.IsSeen }; bdd.T_Message.Add(newMessage); bdd.SaveChanges(); return(true); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(false); } }
public static List <DBO.Message> GetListMessageByUser(long user_id) { List <DBO.Message> result = new List <DBO.Message>(); try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { List <T_Message> list = bdd.T_Message.Where(x => x.id_sender == user_id || x.id_receiver == user_id).ToList(); foreach (T_Message message in list) { DBO.Message newMessage = new DBO.Message() { Content = message.content, Date = message.date, Id = message.id, IdReceiver = message.id_receiver, IdSender = message.id_sender, IsSeen = message.isSeen.Value }; result.Add(newMessage); } return(result); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(result); } }
public void addToConv(DBO.Message message, DBO.User user, ref List <DBO.Conversation> conversations) { foreach (var conversation in conversations) { if (conversation.FriendName.Equals(user.Firstname + " " + user.Lastname)) { if (conversation.LastMessageDate <= message.Date) { conversation.LastMessageDate = message.Date; conversation.LastMessageContent = message.Content; conversation.wasRead = message.IdSender == user.Id ? message.IsSeen : true; } return; } } conversations.Add(new DBO.Conversation() { FriendId = user.Id, FriendName = user.Firstname + " " + user.Lastname, LastMessageDate = message.Date, LastMessageContent = message.Content, wasRead = message.IdSender == user.Id ? message.IsSeen : true }); }
public ActionResult Conversation(int friend_id, int userId = 0) { int user_id = Int32.Parse(HttpContext.Session["UserID"].ToString()); DBO.Message newMessage = new DBO.Message() { Content = Request["Content"], Date = DateTime.Now, IdReceiver = friend_id, IdSender = user_id, IsSeen = false }; if (!BusinessManagement.Message.CreateMessage(newMessage)) { ViewBag.Error = Resources.Views.Message.Conversation.error_send; } return(View(BusinessManagement.Message.GetConversationMessageList(user_id, friend_id))); }
public static bool UpdateMessage(DBO.Message message) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Message oldMessage = bdd.T_Message.Where(x => x.id == message.Id).FirstOrDefault(); oldMessage.content = message.Content; oldMessage.date = message.Date; oldMessage.id_receiver = message.IdReceiver; oldMessage.id_sender = message.IdSender; oldMessage.isSeen = message.IsSeen; bdd.SaveChanges(); return(true); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(false); } }
public static bool CreateMessage(DBO.Message message) { return(DataAccess.Message.CreateMessage(message)); }