Exemplo n.º 1
0
        public VMMessage(MessageBox boxMessage, bool keepbody)
            : this(boxMessage.Message,keepbody)
        {
            this.Sender = boxMessage.From;

            this.To = boxMessage.To;
            this.BoxId = boxMessage.Id;

            if (boxMessage.ReplyedOn.HasValue)
            {
                this.ReplyedOn = boxMessage.ReplyedOn.Value.ToString("dd-MMM-yyyy hh:mm");
            }
        }
Exemplo n.º 2
0
        public bool Send(Message newMessage, IEnumerable<UserProfileInfo> destinations, int? replyTo)
        {
            bool result = true;
            string Tos = destinations.Select(u => u.DisplayName).Aggregate((current, next) => current + ", " + next);

            foreach (var sendTo in destinations)
            {
                MessageBox received = new MessageBox()
                {
                    MessageId = newMessage.Id,
                    UserId = sendTo.Id,
                    BoxType = BoxType.Inbox,
                    From = newMessage.CreatedBy.DisplayName,
                    To = Tos
                };
                dbContext.MessageBoxes.Add(received);

            }
            MessageBox sent = new MessageBox()
            {
                MessageId = newMessage.Id,
                UserId = newMessage.CreatedBy.Id,
                BoxType= BoxType.Outbox,
                From = newMessage.CreatedBy.DisplayName,
                    To = Tos
            };
            dbContext.MessageBoxes.Add(sent);

            if (replyTo.HasValue)
            {// reply to a message, set the repliedOn
                var replyedMsg = this.GetBox(newMessage.CreatedBy.Id, BoxType.Inbox).Where(msg => msg.MessageId == replyTo.Value).FirstOrDefault();
                if (replyedMsg != null)
                {
                    replyedMsg.ReplyedOn = DateTime.Now;
                    dbContext.Entry(replyedMsg).State = EntityState.Modified;
                }
            }

            dbContext.SaveChanges();
            return result;
        }