Esempio n. 1
0
        public UserMessageViewModel(Message message)
        {
            if (message == null)
                return;

            Id = message.Id;
            IsInbox = UserContext.Current.Id != message.AuthorId;

            if (message.AuthorId.HasValue)
            {
                AuthorId = message.AuthorId;
                AuthorFullName = ((User)message.Author).FullName;
            }

            RecipientId = message.RecipientId;
            RecipientFullName = ((User)message.Recipient).FullName;

            Text = message.Text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Summary = TextHelper.CleanTags(message.Text);
            if (Summary.Length > ConstHelper.MessageSummaryLength)
                Summary = Summary.Substring(0, ConstHelper.MessageSummaryLength) + "…";

            Html = message.Text;
            Date = message.Date;
            IsRead = message.IsRead;
            Type = message.Type;
        }
Esempio n. 2
0
        public UserDialog_MessageViewModel(Message message)
        {
            if (message == null)
                return;

            Id = message.Id;
            Text = message.Text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Html = message.Text;
            Date = message.Date.ToFormattedUserTime(UserContext.Current);
            IsRead = message.IsRead;
            IsInbox = UserContext.Current.Id != message.AuthorId;
            Type = (MessageType)message.Type;
        }
Esempio n. 3
0
        public UserDialogs_DialogViewModel(Message message)
        {
            if (message == null)
                return;

            if (message.AuthorId.HasValue)
            {
                var contact = UserContext.Current.Id != message.AuthorId ? (User)message.Author : (User)message.Recipient;
                ContactId = contact.Id;
                ContactName = contact.FirstName + " " + contact.SurName;
                ContactAvatar = ImageService.GetImageUrl<User>(contact.Avatar);
            }

            var text = TextHelper.CleanTags(message.Text);
            MessageSummary = text.Length > ConstHelper.MessageSummaryLength ? text.Substring(0, ConstHelper.MessageSummaryLength) + "…" : text;

            DateTime = message.Date;
            IsInbox = UserContext.Current.Id != message.AuthorId;
            IsRead = message.IsRead;
        }
Esempio n. 4
0
 public PrivateMessageUpdate(Message message)
     : base(message)
 {
     var author = (User)message.Author;
     AuthorAvatar = ImageService.GetImageUrl<User>(author.Avatar, false);
     AuthorUrl = UrlHelper.GetUrl<User>(author.Id, false);
     AuthorName = author.SurName + " " + author.FirstName;
     AnswerUrl = ConstHelper.AppUrl + "/user/sendmessage?replyTo=" + Id;
 }
Esempio n. 5
0
 public MessageUpdate(Message message)
 {
     Id = message.Id;
     Date = message.Date;
     Text = message.Text;
 }
Esempio n. 6
0
        public Message Send(MessageStruct messageInfo)
        {
            if (DataService.PerThread.BaseUserSet.Count(u => u.Id == messageInfo.RecipientId) == 0)
                throw new BusinessLogicException("Получатель не найден!");

            if (messageInfo.AuthorId.HasValue)
            {
                if (DataService.PerThread.BaseUserSet.SingleOrDefault(u => u.Id == messageInfo.AuthorId) == null)
                    throw new BusinessLogicException("Отправитель не найден!");

                if (messageInfo.AuthorId == messageInfo.RecipientId)
                    throw new BusinessLogicException("Нельзя посылать самому себе!");
            }

            var message = new Message
            {
                AuthorId = messageInfo.AuthorId,
                Date = messageInfo.Date,
                RecipientId = messageInfo.RecipientId,
                Text = messageInfo.Text,
                Type = messageInfo.Type,
                IsDeletedByAuthor = false,
                IsDeletedByRecipient = false
            };

            DataService.PerThread.MessageSet.AddObject(message);
            DataService.PerThread.SaveChanges();

            UserContextService.Abandon(message.RecipientId);

            return message;
        }