Example #1
0
 public ActionResult Compose()
 {
     UserMessage model = new UserMessage() { };
     model.Owner = model.Sender = userManagementService.GetUser(SessionManager.CurrentUsername);
     MessageMailBoxItemViewModel newMessage = AutoMapperConfiguration.GetMapper().Map<MessageMailBoxItemViewModel>(model);
     return View(newMessage);
 }
Example #2
0
        public UserMessage SaveMessage(string userName, UserMessage newMessage)
        {
            if (newMessage.Owner.Username == userName)
            {
                return this.Repository.SaveMessage(newMessage);
            }

            return null;
        }
Example #3
0
        public UserMessage SaveMessage(UserMessage sentMessage)
        {
            using (var context = new PhobosCoreContext())
            {
                sentMessage.Owner = context.Users.Include(x => x.Roles).First(x => x.Username == sentMessage.Owner.Username);
                sentMessage.Sender = context.Users.Include(x => x.Roles).First(x => x.Username == sentMessage.Sender.Username);
                sentMessage.Receiver = context.Users.Include(x => x.Roles).First(x => x.Username == sentMessage.Receiver.Username);

                if (sentMessage.Folder == null && sentMessage.IsDraft)
                {
                    sentMessage.Folder = context.UserMessageFolders.FirstOrDefault(x => x.User.Username == sentMessage.Owner.Username && x.Name == DraftFolderName);
                    sentMessage.IsDraft = sentMessage.Folder.Name == DraftFolderName;
                }
                else if (sentMessage.Folder == null && !sentMessage.IsDraft)
                {
                    sentMessage.Folder = context.UserMessageFolders.FirstOrDefault(x => x.User.Username == sentMessage.Receiver.Username && x.Name == InboxFolderName);
                }
                else if (sentMessage.Folder != null)
                {
                    sentMessage.Folder = context.UserMessageFolders.FirstOrDefault(x => x.Id == sentMessage.Folder.Id);
                }

                if (sentMessage.Id == 0)
                {
                    context.UserMessages.Add(sentMessage);
                }
                else
                {
                    context.UserMessages.First(x => x.Id == sentMessage.Id).Message = sentMessage.Message;
                    context.UserMessages.First(x => x.Id == sentMessage.Id).Title = sentMessage.Title;
                    context.UserMessages.First(x => x.Id == sentMessage.Id).Receiver = sentMessage.Receiver;
                    context.UserMessages.First(x => x.Id == sentMessage.Id).Sent = sentMessage.Sent;
                    context.UserMessages.First(x => x.Id == sentMessage.Id).IsFavorite = sentMessage.IsFavorite;
                }

                context.SaveChanges();

                return sentMessage;
            }
        }
Example #4
0
        public UserMessage SendMessage(string userName, UserMessage createdMessage)
        {
            UserMessageFolder sentFolder = this.Repository.GetSentFolder(userName);

            if (createdMessage.Sender.Username == userName)
            {
                //// Create a new instance of this message and send it;
                UserMessage sentMessage = new UserMessage()
                {
                    Attachments = createdMessage.Attachments,
                    Folder = createdMessage.Folder,
                    HasAttachment = createdMessage.HasAttachment,
                    IsFavorite = createdMessage.IsFavorite,
                    Message = createdMessage.Message,
                    Title = createdMessage.Title,
                    MessageDate = DateTime.Now,
                    SendDate = DateTime.Now,
                    Owner = new UserAccount() { Username = createdMessage.Receiver.Username },
                    Receiver = new UserAccount() { Username = createdMessage.Receiver.Username },
                    Sender = new UserAccount() { Username = createdMessage.Owner.Username },
                    Sent = true,
                    IsDraft = false
                };
                this.Repository.SaveMessage(sentMessage);

                //// Mark the current message as Sent.
                createdMessage.Sent = true;
                createdMessage.SendDate = DateTime.Now;
                createdMessage.Folder = sentFolder;
                this.Repository.SaveMessage(createdMessage);
            }

            return createdMessage;
        }
Example #5
0
        public void UserMessage()
        {
            var userMsg = new UserMessage();

            Assert.AreEqual(userMsg.Message, "");
        }
 public UserMessage SaveMessage(UserMessage sentMessage)
 {
     throw new NotImplementedException();
 }