Exemple #1
0
        public VMMessage(Message message)
            : this(message, false)
        {
            if (!String.IsNullOrEmpty(message.Body))
            {
                int displayedSize = MESSAGE_MAX_SIZE;
                int indexOfFirstCarriageReturn = message.Body.IndexOf('\n');
                if (indexOfFirstCarriageReturn>0)
                {
                    displayedSize = indexOfFirstCarriageReturn;
                }
                bool isLongMessage = message.Body.Length > Math.Min(displayedSize,MESSAGE_MAX_SIZE);

                if (isLongMessage)
                {
                    this.Body = message.Body.Substring(0, displayedSize) + "...";
                    this.IsAbstract = true;
                }
                else
                {
                    this.Body = message.Body;
                    this.IsAbstract = false;
                }
            }
        }
Exemple #2
0
 public VMMessage(Message message, bool keepBody)
 {
     Sender = message.CreatedBy.DisplayName;
     SentOn = message.CreatedOn.ToString("dd-MMM-yyyy hh:mm");
     Title = message.Title;
     Id = message.Id;
     To = message.SentTo;
     this.Body = message.Body;
     this.IsAbstract = false;
     ReplyToLogin = message.CreatedBy.Login;
 }
Exemple #3
0
        public void MessageService_Send()
        {
            //Arrange
            List<UserProfileInfo> dummyUsers = serviceUser.GetAll().ToList();
            Message test = new Message() { Body = "TEST", Title = "Title", Tag = "tag1#tag2" };
            var destinationIds = dummyUsers.Select(x => x.Id).ToList();

            //act
            var result = serviceMessage.Send(test,serviceUser.GetCurrentUser(), destinationIds,null);

            Assert.IsTrue(result.Id > 0);
        }
Exemple #4
0
        public void MessageService_TestArchiveInbox()
        {
            //Arrange
            List<UserProfileInfo> dummyUsers = serviceUser.GetAll().ToList();
            Message test = new Message() { Body = "TEST MessageService_TestArchiveInbox", Title = "Title", Tag = "tag1#tag2" };
            var destinationIds = dummyUsers.Select(x => x.Id).ToList();
            serviceMessage.Send(test, serviceUser.GetCurrentUser(),destinationIds,null);
            var currentUser = serviceUser.GetCurrentUser();
            var inbox = serviceMessage.GetFolder(currentUser.Id, MogConstants.MESSAGE_INBOX).ToList();
            var firstMessage = inbox[0];
            int inboxCount = inbox.Count;

            //Act
            serviceMessage.Archive(firstMessage.BoxId, currentUser);

            //Assert
            inbox = serviceMessage.GetFolder(currentUser.Id, MogConstants.MESSAGE_INBOX).ToList();
            Assert.IsTrue(inboxCount != inbox.Count);
        }
Exemple #5
0
        public Message Send(Message newMessage, UserProfileInfo from, IEnumerable<int> destinationIds, int? replyTo = null)
        {
            bool result = true;
            IEnumerable<UserProfileInfo> destinations = serviceUser.GetByIds(destinationIds);

            newMessage.CreatedBy = from;
            newMessage.CreatedOn = DateTime.Now;
            newMessage.SentTo = destinations.Select(u => u.DisplayName).Aggregate((current, next) => current + ", " + next);

            result &= repositoryMessage.Create(newMessage);

            result &= repositoryMessage.Send(newMessage, destinations,replyTo);
            return newMessage;
        }
Exemple #6
0
        public JsonResult Send(string to, string body, string title, int?  replyTo)
        {
            IEnumerable<int> destinationIds = this.serviceMessage.GetDestinationIds(to);
            Message message = new Message() { Body = body, Title = title };
            message = this.serviceMessage.Send(message,CurrentUser, destinationIds, replyTo);
            //todo  : use automapper
            VMMessage vm = new VMMessage(message);

            var result = new JsonResult() { Data = vm, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            return result;
        }
Exemple #7
0
 public bool Create(Message newMessage)
 {
     dbContext.Messages.Add(newMessage);
     int result = dbContext.SaveChanges();
     return (result > 0);
 }
Exemple #8
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;
        }