public static async Task <CommentsGroup> GetCommentsAsync(int id) { var matches = _commentsSource.Comments.Where(n => n.Id == id); if (matches.Count() == 0) { Uri RequestUri = new Uri("https://www.foodlook.az/api/comments/list/" + id.ToString() + "/?order=asc"); string JsonDataString = await Api.GetJsonDataAsync(RequestUri); if (JsonDataString == null) { return(null); } else { var NewComments = new CommentsGroup(id, JsonDataString); _commentsSource.Comments.Add(NewComments); return(NewComments); } } else { return(matches.First()); } }
public static async Task <bool> LoadMoreCommentsAsync(int id) { var matches = _commentsSource.Comments.Where(n => n.Id == id); if (matches.Count() == 0) { return(false); } else { Uri RequestUri = matches.First().NextPageUri; if (RequestUri == null) { return(false); } else { string JsonDataString = await Api.GetJsonDataAsync(RequestUri); if (JsonDataString == null) { return(false); } else { var NewComments = new CommentsGroup(id, JsonDataString); var GroupIndex = _commentsSource.Comments.IndexOf(matches.First()); foreach (var comment in NewComments.Comments) { if (_commentsSource.Comments[GroupIndex].Comments.Where(n => n.Id == comment.Id).Count() == 0) { _commentsSource.Comments[GroupIndex].Comments.Add(comment); } } _commentsSource.Comments[GroupIndex].NextPageUri = NewComments.NextPageUri; return(true); } } } }