示例#1
0
        public bool SendMessage(string sender, ArrayList receiver, string messageContent)
        {
            try {
                List <string> receiverList = new List <string>();
                foreach (var item in receiver)
                {
                    string userId = getAspNetUserIdByName(item.ToString());
                    if (userId != null)
                    {
                        receiverList.Add(userId);
                    }
                }

                if (receiverList.ToArray().Length > 0)
                {
                    Message messageSender = new Message();
                    messageSender.SenderID          = getAspNetUserIdByName(sender);
                    messageSender.Message_content   = messageContent;
                    messageSender.IsCanceled        = false;
                    messageSender.IsDeletedBySender = false;
                    messageSender.SendTime          = DateTime.Now;
                    MessageRepository.Insert(messageSender);
                    Save();

                    int id = MessageRepository.Get().LastOrDefault().MessageID;

                    MessageReceiver messageReceiver = null;
                    foreach (var item in receiverList)
                    {
                        messageReceiver            = new MessageReceiver();
                        messageReceiver.ReceiverID = item.ToString();
                        messageReceiver.IsDeleted  = false;
                        messageReceiver.MessageID  = id;

                        MessageReceiverRepository.Insert(messageReceiver);
                        Save();
                    }
                }
                return(true);
            }
            catch (Exception e) {
                return(false);
            }
        }
示例#2
0
        public void deleteMessage(string userId, List <int> list, string messageRole)
        {
            List <MessageReceiver> messageList     = new List <MessageReceiver>();
            List <Message>         messageSendList = new List <Message>();

            if ("allMessage".Equals(messageRole))
            {
                foreach (var item in list)
                {
                    var message = MessageReceiverRepository.Get(filter: m => m.ReceiverID == userId && m.MessageID == item).FirstOrDefault();
                    message.IsDeleted = true;
                    messageList.Add(message);
                }

                foreach (var item in messageList)
                {
                    MessageReceiverRepository.Update(item);
                    Save();
                }
            }

            if ("sentMessage".Equals(messageRole))
            {
                foreach (var item in list)
                {
                    var message = MessageRepository.Get(filter: m => m.SenderID == userId && m.MessageID == item).FirstOrDefault();
                    message.IsDeletedBySender = true;
                    messageSendList.Add(message);
                }

                foreach (var item in messageSendList)
                {
                    MessageRepository.Update(item);
                    Save();
                }
            }
        }