public MessageViewModel(Message message)
        {
            Id = message.Id;
            From = message.From ?? string.Empty;
            Content = message.Content ?? string.Empty;
            Subject = message.Subject ?? string.Empty;

            if (message.User != null)
                User = new UserViewModel(message.User);

            When = message.When;
        }
        private void ProcessNonAuth(Message.NotAuthorizedMessage msg)
        {
            if (!msg.IsTriedToLog)
            {
                var dialogMsg = new GalaSoft.MvvmLight.Messaging.DialogMessage("You are not authorized.\n\r Continue authorization?", res =>
                {
                    if (res == MessageBoxResult.OK)
                        ProcessLoginCommand.Execute(null);
                    else
                    {
                        //App.Current.MainWindow.OwnedWindows[0].Close();
                        App.Current.Shutdown(0);
                    }

                });
                dialogMsg.Button = MessageBoxButton.OKCancel;
                Messenger.Default.Send(dialogMsg, "msg1");
            }
        }
        private void ProcessLoginResult(Message.LoginResultMessage message)
        {
            if (message != null && message.LoginResult != null)
            {
                LoginResult = message.LoginResult;
                if (message.LoginResult.IsAuthorized && _outlookInitTask.Status == TaskStatus.Created)
                    _outlookInitTask.Start();

                _afterloginTask.Start();
            }
        }
        private void OnNewGroup(Message.NewGroupMessage msg)
        {
            GalaSoft.MvvmLight.Threading.DispatcherHelper.InvokeAsync(() =>
            {
                var newGroupView = App.Current.MainWindow.OwnedWindows.Cast<Window>().FirstOrDefault();
                if (newGroupView != null)
                    newGroupView.Close();

                if (msg.NewGroup != null)
                    UserGroups.Add(msg.NewGroup);
            });
        }
 private void OnDefaultChanging(Message.ChangeGroupMessage msg)
 {
     if (msg.DefaultGroup != null)
     {
         GroupToSend = msg.DefaultGroup;
     }
 }
        private void LoginPerformed(Message.LoginMessage loginMsg)
        {
            if (loginMsg != null)
            {
                LoginData = loginMsg.Login;
                IsLogged = true;
            }

            var window = App.Current.MainWindow.OwnedWindows.Cast<Window>().FirstOrDefault();
            if (window != null)
                window.Close();

            GC.Collect();
        }
        public Common.Models.Message AddMessage(Common.Models.MessangerUser user, Common.Models.MessangerGroup group, string id, string content)
        {
            var message = new Message
            {
                Id = id,
                User = user,
                Content = content,
                When = DateTimeOffset.UtcNow,
                Group = group
            };

            _repository.Add(message);

            return message;
        }