Esempio n. 1
0
        async Task ExecuteLoadMessages()
        {
            Messages.Clear();
            IsBusy = true;
            var messages = await MessageDataStore.GetMessagesAsync(true);

            var sendId  = SenderId;
            var recipId = Recip.Id;

            messages = messages.OrderBy(s => s.SendDate);
            foreach (var msg in messages)
            {
                if (msg.ToId.Equals(recipId) && msg.FromId.Equals(sendId))
                {
                    msg.Text = "Wysłano: " + msg.Text;
                    Messages.Add(msg);
                }
                if (msg.FromId.Equals(recipId) && msg.ToId.Equals(sendId))
                {
                    msg.Text = "Odebrano: " + msg.Text;
                    Messages.Add(msg);
                }
            }
            IsBusy = false;
        }
Esempio n. 2
0
        async Task ExecutLoadMessages()
        {
            Messages.Clear();
            IsBusy = true;
            var messages = await MessageDataStore.GetItemsAsync(true);

            var userID      = LoggedUser.User.Id;
            var recipientID = Recipient.Id;

            messages = messages.OrderBy(s => s.Date);
            foreach (var message in messages)
            {
                if (message.RecipentId.Equals(recipientID) && message.SenderId.Equals(userID))
                {
                    message.Content = "Wysłano: " + message.Content;
                    Messages.Add(message);
                }
                if (message.SenderId.Equals(recipientID) && message.RecipentId.Equals(userID))
                {
                    message.Content = $"{Recipient.Name} napisał: " + message.Content;
                    Messages.Add(message);
                }
            }
            IsBusy = false;
        }
Esempio n. 3
0
 public TalkViewModel(Student recipient)
 {
     Title        = recipient.Name + " " + recipient.Surname;
     Recipient    = recipient;
     Messages     = new ObservableCollection <Message>();
     LoadMessages = new Command(async() => await ExecutLoadMessages());
     MessagingCenter.Subscribe <TalkPage, Message>(this, "SendMessage", async(obj, message) =>
     {
         var newMessage = message as Message;
         await MessageDataStore.AddItemAsync(newMessage);
         Messages.Add(newMessage);
     });
 }
Esempio n. 4
0
        public ChatViewModel(Student recip, string senderId)
        {
            Recip    = recip;
            Title    = Recip.FirstName;
            SenderId = senderId;
            Messages = new ObservableCollection <Message>();

            LoadMessagesCommand = new Command(async() => await ExecuteLoadMessages());
            MessagingCenter.Subscribe <ChatPage, Message>(this, "SendMessage", async(obj, message) =>
            {
                var newMessage = message as Message;
                await MessageDataStore.AddMessageAsync(newMessage);
                Messages.Add(newMessage);
            });
        }
        public override Message CreateMessage(Topic topic, string idParentMessage, string owner, string title, string body, Attachment.FileInfo attachment)
        {
            //Check attachment
            if (attachment != null)
                Attachment.FileHelper.CheckFile(attachment, topic.Category.AttachExtensions, topic.Category.AttachMaxSize);

            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                TopicDataStore topicStore = new TopicDataStore(transaction);
                topicStore.Attach(topic);

                MessageDataStore messageStore = new MessageDataStore(transaction);
                Message parentMessage = messageStore.FindByKey(idParentMessage);
                if (parentMessage == null)
                    throw new MessageNotFoundException(idParentMessage);

                Message newMessage = new Message(topic, idParentMessage, owner, title, body, attachment);

                messageStore.Insert(newMessage);

                transaction.Commit();

                //Notify user for answer
                NotifyUserReply(parentMessage, newMessage);

                return newMessage;
            }
        }
        /// <summary>
        /// Recursively delete all the messages and the relative attachments
        /// </summary>
        protected virtual void InternalDeleteMessage(MessageDataStore store,
                                                TransactionScope transaction, Message obj)
        {
            //Recursively delete any child message
            IList<Message> children = store.FindByParent(obj.Id);
            foreach (Message childMsg in children)
                InternalDeleteMessage(store, transaction, childMsg);

            store.Delete(obj.Id);
        }
        public override int MessageCountByTopic(Topic topic)
        {
            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                MessageDataStore store = new MessageDataStore(transaction);

                return store.MessageCountByTopic(topic);
            }
        }
        /// <summary>
        /// Get a list of messages for the specified topic ordered by InsertDate
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public override IList<Message> GetMessagesByTopic(Topic topic)
        {
            //TODO Evaluate if is better to returns a light object to don't load all the attachments and the forum data

            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                MessageDataStore store = new MessageDataStore(transaction);

                return store.FindByTopic(topic);
            }
        }
        public override Message GetMessage(string id)
        {
            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                MessageDataStore store = new MessageDataStore(transaction);
                Message msg = store.FindByKey(id);
                if (msg == null)
                    throw new MessageNotFoundException(id);

                return msg;
            }
        }
        public override IList<Message> FindMessages(Filter<string> categoryName,
                                           Filter<string> searchFor,
                                           Filter<string> owner,
                                           Filter<string> tag,
                                           DateTime? fromDate, DateTime? toDate,
                                           PagingInfo paging)
        {
            //TODO Evaluate if is better to returns a light object to don't load all the attachments and the forum data

            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                MessageDataStore store = new MessageDataStore(transaction);

                return store.FindByFields(categoryName, searchFor, owner, tag, fromDate, toDate, paging);
            }
        }
        public override void DeleteMessage(Message message)
        {
            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                MessageDataStore store = new MessageDataStore(transaction);

                InternalDeleteMessage(store, transaction, message);

                transaction.Commit();
            }
        }
        /// <summary>
        /// Create the topic and the relative root message.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="owner"></param>
        /// <param name="title"></param>
        /// <param name="body"></param>
        /// <param name="attachment">Use null if you don't have any attachment</param>
        /// <param name="topic">Returns the topic created</param>
        /// <param name="rootMessage">Returns the message created</param>
        public override void CreateTopic(Category category, string owner,
                                          string title, string body, Attachment.FileInfo attachment,
                                          out Topic topic,
                                          out Message rootMessage)
        {
            //Check attachment
            if (attachment != null)
                Attachment.FileHelper.CheckFile(attachment, category.AttachExtensions, category.AttachMaxSize);

            using (TransactionScope transaction = new TransactionScope(Configuration))
            {
                CategoryDataStore forumStore = new CategoryDataStore(transaction);
                forumStore.Attach(category);

                //Insert topic
                TopicDataStore topicStore = new TopicDataStore(transaction);
                topic = new Topic(category, owner, title);
                topicStore.Insert(topic);

                //Insert root message
                MessageDataStore messageStore = new MessageDataStore(transaction);
                rootMessage = new Message(topic, null, owner, title, body, attachment);
                messageStore.Insert(rootMessage);

                transaction.Commit();
            }
        }