Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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
            });
        }
Example #4
0
        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)));
        }
Example #5
0
 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);
     }
 }
Example #6
0
 public static bool CreateMessage(DBO.Message message)
 {
     return(DataAccess.Message.CreateMessage(message));
 }