Example #1
0
 public WindowMailMessageViewModel(MailUserControl mailUserControl, UserMail message, WindowMailMessage windowMailMessage)
 {
     this.windowMailMessage = windowMailMessage;
     this.mailUserControl   = mailUserControl;
     this.message           = message;
     BodyMessage            = message.BodyMessage;
     Heading     = message.Heading;
     TimeMessage = message.TimeMessage;
 }
        public WindowMailMessage(MailUserControl mailUserControl, UserMail message)
        {
            InitializeComponent();
            this.mailUserControl = mailUserControl;
            WindowMailMessageViewModel windowMailMessageViewModel = new WindowMailMessageViewModel(mailUserControl, message, this);

            DataContext = windowMailMessageViewModel;
            this.mailUserControl.timer.Stop();
            this.mailUserControl.ComboBoxRecipients_SelectionChanged();
        }
        public MailUserControlViewModel(MailUserControl mailUserControl)
        {
            this.mailUserControl = mailUserControl;
            eventSelection       = (sender, e) =>
            {
                if (mailUserControl.ComboBoxRecipients.SelectedItem != null)
                {
                    mailUserControl.StackPanelMessage.Children.Clear();
                    ObservableCollection <UserMail> MailsSort = new ObservableCollection <UserMail>(GliderDataContext.Instance.UserMail.ToList());
                    mails.Clear();
                    User recCombobox = (User)mailUserControl.ComboBoxRecipients.SelectedItem;
                    foreach (UserMail item in MailsSort)
                    {
                        if (item.Sender == mailUserControl.Login && item.Recipient == recCombobox.Login || item.Sender == recCombobox.Login && item.Recipient == mailUserControl.Login)
                        {
                            mails.Add(item);
                        }
                    }
                    foreach (UserMail item in Mails)
                    {
                        if (item.Sender == mailUserControl.Login)
                        {
                            MessageUserControl message = new MessageUserControl();
                            message.DataContext         = item;
                            message.HorizontalAlignment = HorizontalAlignment.Right;
                            mailUserControl.StackPanelMessage.Children.Add(message);
                        }
                        else if (item.Sender == recCombobox.Login)
                        {
                            MessageRecipientsUserControl message = new MessageRecipientsUserControl();
                            message.DataContext         = item;
                            message.HorizontalAlignment = HorizontalAlignment.Left;
                            mailUserControl.StackPanelMessage.Children.Add(message);
                        }
                    }
                }
                else
                {
                    mailUserControl.StackPanelMessage.Children.Clear();
                }
                mailUserControl.ScrollViewrMessage.ScrollToBottom();
            };
            users = new List <User>(GliderDataContext.Instance.Users.ToList());
            GliderDataContext gliderDataContext = GliderDataContext.Instance;
            User this_user = gliderDataContext.Users.FirstOrDefault(u => u.Login == mailUserControl.Login);

            users.Remove(this_user);
            eventSendMessage = (sender, e) =>
            {
                if (mailUserControl.ComboBoxRecipients.Text != null)
                {
                    mailUserControl.ComboBoxRecipients.Text = userSender.Sender;
                    mailUserControl.StackPanelMessage.Children.Clear();
                    ObservableCollection <UserMail> MailsSort = new ObservableCollection <UserMail>(GliderDataContext.Instance.UserMail.ToList());
                    mails.Clear();
                    foreach (UserMail item in MailsSort)
                    {
                        if (item.Sender == mailUserControl.Login && item.Recipient == mailUserControl.ComboBoxRecipients.Text || item.Sender == mailUserControl.ComboBoxRecipients.Text && item.Recipient == mailUserControl.Login)
                        {
                            mails.Add(item);
                        }
                    }
                    foreach (UserMail item in Mails)
                    {
                        if (item.Sender == mailUserControl.Login)
                        {
                            MessageUserControl message = new MessageUserControl();
                            message.DataContext         = item;
                            message.HorizontalAlignment = HorizontalAlignment.Right;
                            mailUserControl.StackPanelMessage.Children.Add(message);
                        }
                        else if (item.Sender == mailUserControl.ComboBoxRecipients.Text)
                        {
                            MessageRecipientsUserControl message = new MessageRecipientsUserControl();
                            message.DataContext         = item;
                            message.HorizontalAlignment = HorizontalAlignment.Left;
                            mailUserControl.StackPanelMessage.Children.Add(message);
                        }
                    }
                }
                else
                {
                    mailUserControl.StackPanelMessage.Children.Clear();
                }
                mailUserControl.ScrollViewrMessage.ScrollToBottom();
            };
            eventTimer = (sender, e) =>
            {
                ObservableCollection <UserMail> MailsTimer = new ObservableCollection <UserMail>(GliderDataContext.Instance.UserMail.ToList());
                foreach (UserMail item in MailsTimer)
                {
                    if (item.Recipient == mailUserControl.Login && item.Done == false)
                    {
                        userSender.Sender = item.Sender;
                        WindowMailMessage windowMailMessage = new WindowMailMessage(mailUserControl, item);
                        windowMailMessage.Show();
                    }
                }
            };
        }