Пример #1
0
 public DisplayMessageViewData(UserMessages userMessage)
     : base(userMessage)
 {
     Body = userMessage.Message.Text;
     Attachments = userMessage.Message.Attachments;
     Date = userMessage.Date.ToString("F", new CultureInfo("ru-RU"));
 }
Пример #2
0
        public UserMessages SaveUserMessages(UserMessages userMessages)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.MessageRepository.SaveUserMessages(userMessages);
                repositoriesContainer.ApplyChanges();
            }

            return userMessages;
        }
Пример #3
0
 public MessagesViewData(UserMessages userMessage)
 {
     Id = userMessage.MessageId;
     AthorName = userMessage.Author.FullName;
     AthorId = userMessage.Author.Id.ToString();
     Subject = userMessage.Message.Subject;
     PreviewText = !string.IsNullOrEmpty(userMessage.Message.Text)
         ? userMessage.Message.Text.Substring(0, Math.Min(userMessage.Message.Text.Length, 100))
         : userMessage.Message.Text;
     IsRead = userMessage.IsRead;
     Date = userMessage.Date.ToString(userMessage.Date.Date == DateTime.Now.Date ? "t" : "d", new CultureInfo("ru-RU"));
     Recipients = MessageManagementService.GetMessageRecipients(userMessage.MessageId)
         .Select(e => string.IsNullOrEmpty(e.FullName) ? e.UserName : e.FullName);
     AttachmentsCount = userMessage.Message.Attachments.Any() ? userMessage.Message.Attachments.Count : 0;
 }
Пример #4
0
 public DisplayMessageViewModel(UserMessages userMessages)
 {
     InitFields(userMessages);
 }
Пример #5
0
 private void InitFields(UserMessages userMessages)
 {
     AuthorName = userMessages.Author.FullName;
     DateTime = userMessages.Date;
     Text = userMessages.Message.Text;
     MessageId = userMessages.MessageId;
     UserMessageId = userMessages.Id;
     AuthorId = userMessages.AuthorId;
     IsRead = userMessages.IsRead;
     Subject = userMessages.Message.Subject;
     HasAttachments = userMessages.Message.Attachments.Any();
 }
Пример #6
0
        public static DisplayMessageViewModel FormMessageToDisplay(UserMessages userMessages)
        {
            var model = new DisplayMessageViewModel(userMessages);

            return model;
        }
Пример #7
0
        public void SaveMessage()
        {
            var msg = new Message(MessageText, Subject);

            if (Attachment != null && Attachment.Any())
            {
                msg.AttachmentsPath = Guid.NewGuid();
                Attachment.ForEach(a => a.PathName = msg.AttachmentsPath.ToString());
                msg.Attachments = Attachment;
            }

            MessageManagementService.SaveMessage(msg);

            if (ToAdmin)
            {
                var admin = UserManagementService.GetAdmin();
                var userMsg = new UserMessages(admin.Id, FromId, msg.Id);
                MessageManagementService.SaveUserMessages(userMsg);
            }
            else
            {
                foreach (var recipient in Recipients)
                {
                    var userMsg = new UserMessages(recipient, FromId, msg.Id);
                    MessageManagementService.SaveUserMessages(userMsg);
                }
            }
        }
Пример #8
0
        public ResultViewData Save(string subject, string body, string recipients, string attachments)
        {
            try
            {
                var attachmentsList = JsonConvert.DeserializeObject<List<Attachment>>(attachments).ToList();
                var recipientsList = JsonConvert.DeserializeObject<List<int>>(recipients).ToList();
                var fromId = WebSecurity.CurrentUserId;

                if (!string.IsNullOrEmpty(subject) && subject.Length > 50)
                {
                    subject = subject.Substring(0, 50);
                }

                var msg = new Message(body, subject);

                if (attachmentsList.Any())
                {
                    msg.AttachmentsPath = Guid.NewGuid();
                    attachmentsList.ForEach(a => a.PathName = msg.AttachmentsPath.ToString());
                    msg.Attachments = attachmentsList;
                }

                MessageManagementService.SaveMessage(msg);

                ////if (ToAdmin)
                ////{
                ////    var admin = UserManagementService.GetAdmin();
                ////    var userMsg = new UserMessages(admin.Id, FromId, msg.Id);
                ////    MessageManagementService.SaveUserMessages(userMsg);
                ////}
                ////else
                ////{
                foreach (var recipientId in recipientsList)
                {
                    var userMsg = new UserMessages(recipientId, fromId, msg.Id);
                    MessageManagementService.SaveUserMessages(userMsg);
                }
                ////}

                return new ResultViewData
                {
                    Message = "Сообщение отправлено",
                    Code = "200"
                };
            }
            catch (Exception e)
            {
                return new ResultViewData
                {
                    Message = "Произошла ошибка при сохранение сообщения",
                    Code = "500"
                };
            }
        }