public void Restore(System.Collections.Generic.IDictionary <string, object> state)
 {
     if (state.ContainsKey("BlogPageComments"))
     {
         _comments = state["BlogPageComments"] as ObservableCollection <Message>;
         result    = state["BlogPageResult"] as PagedResultOfTrainingDayCommentDTO5oAtqRlh;
     }
     setCommentsStatus();
 }
        public void LoadComments()
        {
            result = null;

            if (day == null || day.GlobalId == Guid.Empty)
            {
                _comments.Clear();
                setCommentsStatus();
                onBlogCommentsLoaded();
                return;
            }
            CommentsStatus = ApplicationStrings.BlogViewModel_LoadComments_Loading;
            var m = new ServiceManager <GetTrainingDayCommentsCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetTrainingDayCommentsCompletedEventArgs> operationCompleted)
            {
                client1.GetTrainingDayCommentsAsync(ApplicationState.Current.SessionData.Token, day, new PartialRetrievingInfo());
                client1.GetTrainingDayCommentsCompleted -= operationCompleted;
                client1.GetTrainingDayCommentsCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    onBlogCommentsLoaded();
                    BAMessageBox.ShowError(ApplicationStrings.BlogViewModel_LoadComments_ErrorMsg);
                    return;
                }
                else
                {
                    _comments.Clear();
                    fillComments(a);
                    setCommentsStatus();
                }
                onBlogCommentsLoaded();
            };

            if (!m.Run())
            {
                onBlogCommentsLoaded();
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
 private void fillComments(ServiceManager <GetTrainingDayCommentsCompletedEventArgs> .ServiceManagerOperationResult a)
 {
     result = a.Result.Result;
     foreach (var item in result.Items)
     {
         var msg = new Message();
         msg.User               = item.Profile;
         msg.Picture            = item.Profile.Picture;
         msg.UserName           = item.Profile.UserName;
         msg.Side               = item.Profile.IsMe ? MessageSide.Me : MessageSide.You;
         msg.Text               = item.Comment;
         msg.Timestamp          = item.DateTime;
         msg.TrainingDayComment = item;
         _comments.Add(msg);
     }
 }
        public void LoadMore()
        {
            var m = new ServiceManager <GetTrainingDayCommentsCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetTrainingDayCommentsCompletedEventArgs> operationCompleted)
            {
                client1.GetTrainingDayCommentsAsync(ApplicationState.Current.SessionData.Token, day, new PartialRetrievingInfo()
                {
                    PageIndex = result.PageIndex + 1
                });
                client1.GetTrainingDayCommentsCompleted -= operationCompleted;
                client1.GetTrainingDayCommentsCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    onBlogCommentsLoaded();
                    BAMessageBox.ShowError(ApplicationStrings.BlogViewModel_LoadComments_ErrorMsg);
                    return;
                }
                else
                {
                    result = a.Result.Result;
                    fillComments(a);
                }
                onBlogCommentsLoaded();
            };

            if (!m.Run())
            {
                onBlogCommentsLoaded();
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }