public async void LoadMore() { try { IsLoadingMore = true; pageIndex++; var newMoments = await GetComments(pageIndex, pageSize, Moment.ID); if (newMoments == null || newMoments.Length == 0) { CanLoadMore = false; } else { foreach (var item in newMoments) { MomentComments.Add(item); } } } catch (Exception e) { #if DEBUG Services.NotityService.DisplayAlert("Error", e.Message, "OK"); #else Services.NotityService.Notify("获取数据遇到错误"); #endif } finally { IsLoadingMore = false; } }
public async void LoadAllComments() { try { pageIndex = 0; var re = await GetComments(pageIndex, pageSize, Moment.ID); MomentComments.Clear(); foreach (var item in re) { MomentComments.Add(item); } } catch (Exception e) { #if DEBUG Services.NotityService.DisplayAlert("Error", e.Message, "OK"); #else Services.NotityService.Notify("获取数据遇到错误"); #endif } finally { } }
public async void Refresh() { try { IsRefreshing = true; pageIndex = 0; var re = await GetComments(pageIndex, pageSize, Moment.ID); if (re == null || re.Length == 0) { this.CanLoadMore = false; } else { MomentComments.Clear(); foreach (var item in re) { MomentComments.Add(item); } } } catch (Exception e) { #if DEBUG Services.NotityService.DisplayAlert("Error", e.Message, "OK"); #else Services.NotityService.Notify("获取数据遇到错误"); #endif } finally { IsRefreshing = false; } }
public async void Comment() { if (string.IsNullOrEmpty(CommentContent)) { Services.NotityService.Notify("写点什么呗"); return; } var user = Services.UserService.Instance.UserInfo; if (user == null || user.Username == null || user.Token == null) { await _navigationService.NavigateAsync(typeof(Views.MyBJUT.LoginPage).Name); return; } IsLoading = true; try { var dic = new Dictionary <string, string>(4); dic.Add("MomentID", Moment.ID.ToString()); dic.Add("CommentToID", _selectedComment == null?string.Empty: _selectedComment.ID.ToString()); dic.Add("Content", CommentContent); dic.Add("Username", user.Username); var resultStr = await _httpService.SendRequst(momentsCommentUri, HttpMethod.Post, dic, Authorization : Services.UserService.Instance.Token); var result = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.MyBJUT.MomentCommentResult>(resultStr); if (result.Code == 200) { //insert into top of the comment list; var comment = new MomentCommentsViewModel(); comment.Content = CommentContent; comment.MomentID = Moment.ID; comment.Nickname = user.NickName; comment.Username = user.Username; comment.PostedTime = DateTime.Now; if (_selectedComment != null) { comment.CommentTo = _selectedComment.ID; comment.CommentToUsername = _selectedComment.Username; comment.CommentToNickname = _selectedComment.Nickname; } comment.FilterNicknameAndContent(); MomentComments.Insert(0, comment); CommentContent = string.Empty; _selectedComment = null; SelectedUser = null; Services.NotityService.Notify("评论成功"); } else { Services.NotityService.Notify(result.Msg); } } catch (InvalidUserInfoException) { Services.NotityService.Notify("登录信息失效"); await _navigationService.NavigateAsync(typeof(Views.MyBJUT.LoginPage).Name); } catch { Services.NotityService.Notify("遇到未知错误"); } finally { IsLoading = false; } }