private void FillData() { places = new RelatedPosts(); List <Post> posts = App.Data.Data; if (posts != null && posts.Count > 0) { List <int> placesIds = new List <int>(); foreach (Post item in posts) { if (item == null || item.Content == null) // ignore the post that does not have a content { continue; } if (!Helper.IsExistsInArray(item.Id, misCategory.Posts)) // where this mistake is not related to this category { continue; } switch (item.Type) { case "place": continue; // ignore places case "azkar": // ignore azkar continue; case "ahkam": // ignore ahkam continue; case "mistake": if (item.Relations != null && item.Relations.Place != null) { placesIds.AddRange(item.Relations.Place); } break; } } if (placesIds.Count > 0) // if there is places related to this category { IEnumerable <int> uniquePlaces = placesIds.Distinct <int>(); // distinct the repeated IDs foreach (var id in uniquePlaces) { Post _post = Helper.GetPost(id); if (Helper.IsRelatedToArea(_post, this.AreaId)) // where is place is related to this area { places.Add(_post); } } } } }
public bool DeepEquals(PostSearchResponse?other) { return(other is not null && RelatedPosts.DeepEqualsList(other.RelatedPosts) && Authors.DeepEqualsList(other.Authors) && Groups.DeepEqualsList(other.Groups) && SearchedTags.DeepEqualsList(other.SearchedTags) && Polls.DeepEqualsList(other.Polls) && RecruitmentDetails.DeepEqualsList(other.RecruitmentDetails) && AvailablePages == other.AvailablePages && Results.DeepEqualsList(other.Results) && TotalResults == other.TotalResults && HasMore == other.HasMore && (Query is not null ? Query.DeepEquals(other.Query) : other.Query is null) && ReplacementContinuationToken == other.ReplacementContinuationToken && UseTotalResults == other.UseTotalResults); }
async void Init() { currentMedia = CurrentMedia.Image; ///////////// Initilize Related Post //////////// azkar = new RelatedPosts(AppResources.AzkarAndSupplicationsTitle, AZKAR_ICON_URI, RelatedPostType.Supplications); mistakes = new RelatedPosts(AppResources.MistakesOccurredTitle, MISTAKES_ICON_URI, RelatedPostType.Mistakes); ahkam = new RelatedPosts(AppResources.AhkamAndRulesTitle, AHKAM_ICON_URI, RelatedPostType.Rules); virtue = new RelatedPosts(AppResources.FeaturesAndVirtues, VIRTUE_ICON_URI, RelatedPostType.Virtue); List <Post> posts = App.Data.Data; posts = posts.Where(x => RelatedPosts.IsRelated(x, postData.PostID)).ToList(); if (posts != null && posts.Count > 0) { foreach (Post item in posts) { if (item == null || item.Content == null) // ignore the post that does not have a content { continue; } switch (item.Type) { case "place": continue; // ignore case "azkar": if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Azkar) { azkar.Add(item); } break; case "mistake": if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Mistake) { mistakes.Add(item); } break; case "ahkam": if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Ahkam) { ahkam.Add(item); } break; case "virtue": if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Virtue) { virtue.Add(item); } break; } } } InitializeControls(); imgFavorite.Source = await Helper.GetAutoFavoriteIcon(postData.PostID); MainGrid = new Grid() { Padding = new Thickness(0, -6, 0, 0), VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, RowSpacing = 0, ColumnSpacing = 0, RowDefinitions = { new RowDefinition { Height = new GridLength(.92, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(.08, GridUnitType.Star) }, }, }; RelatedScrollView = new ScrollView() { Content = MainStackLayout }; MainGrid.Children.Add(RelatedScrollView); MainGrid.Children.Add(gridToolBar, 0, 1); this.MainBodyScrollView.Content = null; base.MainForAdjDataView.Children.Add(MainGrid); }
private void Fill_Click(object sender, EventArgs e) { //do we need this? int attId = 0; int tagId = 0; int eVideosId = 0; int fCategoriesId = 0; int rPostId = 0; //define error lists List <Article> articleError = new List <Article>(); List <Attachment> attachmentsError = new List <Attachment>(); List <EmbededVideos> embadedVideosError = new List <EmbededVideos>(); List <FeaturedCategories> featuredCategoriesError = new List <FeaturedCategories>(); List <Meta> metaError = new List <Meta>(); List <RelatedPosts> relatedPostsError = new List <RelatedPosts>(); List <Tag> tagError = new List <Tag>(); foreach (ArticleJSON item in mArticles) { Article tempArticle = new Article(item); tempArticle.IsDeleted = false; tempArticle.LastUpdated = DateTime.Now; db.Articles.Add(tempArticle); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { string exception = ex.ToString(); articleError.Add(tempArticle); } catch (Exception w) { string whatEx = w.ToString(); articleError.Add(tempArticle); } foreach (Attachment att in item.Attachments) { Attachment tempAttachment = new Attachment(); tempAttachment = att; //att.AttachmentId = attId; tempAttachment.ArticleId = tempArticle.Id; // att.Id = item.Id; att.SiteId = item.Local; att.Date = item.Date; db.Attachments.Add(tempAttachment); try { db.SaveChanges(); } #pragma warning disable CS0168 // Variable is declared but never used catch (DbEntityValidationException ea) #pragma warning restore CS0168 // Variable is declared but never used { attachmentsError.Add(tempAttachment); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { attachmentsError.Add(tempAttachment); } int tagsCounter = 0; int maxTags = 10; foreach (string temp in att.tags) { tagsCounter++; Tag tempTag = new Tag() { AttachmentId = tempAttachment.AttachmentId, tag = temp, ArticleId = tempArticle.Id, TagId = tagId }; db.Tags.Add(tempTag); try { db.SaveChanges(); } #pragma warning disable CS0168 // Variable is declared but never used catch (DbEntityValidationException ec) #pragma warning restore CS0168 // Variable is declared but never used { tagError.Add(tempTag); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { tagError.Add(tempTag); } //do we need this? tagId++; //limit tags somehow if (tagsCounter > maxTags) { int tags_currentcounter = att.tags.Count; break; } } attId++; } foreach (string vids in item.Meta.embeddedVideos) { EmbededVideos tempVid = new EmbededVideos() { embededVideos = vids, EmbededVideosId = eVideosId, ArticleId = tempArticle.Id }; db.EmbededVideos.Add(tempVid); try { db.SaveChanges(); } #pragma warning disable CS0168 // Variable is declared but never used catch (DbEntityValidationException eb) #pragma warning restore CS0168 // Variable is declared but never used { embadedVideosError.Add(tempVid); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { embadedVideosError.Add(tempVid); } eVideosId++; } foreach (int cat in item.Meta.featuredCategories) { FeaturedCategories tempCat = new FeaturedCategories() { featuredCategories = cat, FeaturedCategoriesId = fCategoriesId, ArticleId = tempArticle.Id }; db.FeaturedCategories.Add(tempCat); try { db.SaveChanges(); } #pragma warning disable CS0168 // Variable is declared but never used catch (DbEntityValidationException ee) #pragma warning restore CS0168 // Variable is declared but never used { featuredCategoriesError.Add(tempCat); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { featuredCategoriesError.Add(tempCat); } fCategoriesId++; } foreach (int post in item.Meta.relatedPosts) { RelatedPosts tempPosts = new RelatedPosts() { relatedPosts = post, RelatedPostsId = rPostId, ArticleId = tempArticle.Id }; db.RelatedPosts.Add(tempPosts); try { db.SaveChanges(); } #pragma warning disable CS0168 // Variable is declared but never used catch (DbEntityValidationException ed) #pragma warning restore CS0168 // Variable is declared but never used { relatedPostsError.Add(tempPosts); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { relatedPostsError.Add(tempPosts); } rPostId++; } //db.Articles.Add(tempArticle); //db.SaveChanges(); //try //{ // db.SaveChanges(); //} //catch (DBConcurrencyException DBEX) //{ // string dbex = DBEX.ToString(); //} //catch (Exception excwption) //{ // string excet = excwption.ToString(); // throw; //} } //error handling string result = ""; if (articleError.Count > 0 || attachmentsError.Count > 0 || embadedVideosError.Count > 0 || featuredCategoriesError.Count > 0 || metaError.Count > 0 || relatedPostsError.Count > 0 || tagError.Count > 0) { result = "article errors: " + articleError.Count + "\n attachments errors: " + attachmentsError.Count + "\n Videos errors: " + embadedVideosError.Count + "\n categories errors " + featuredCategoriesError.Count + "\n Meta errors" + metaError.Count + "\n Posts errors:" + relatedPostsError.Count + "\n Tags error: " + tagError.Count; } else { result = "Congratulations! Database inserts finnished without error"; } MessageBox.Show(result); }
public static PostHandler ChainPostHandlers(PostHandler baseHandler, Report report, bool forAccountsReport = false) { PostHandler handler = baseHandler; Predicate displayPredicate = null; Predicate onlyPredicate = null; DisplayFilterPosts displayFilter = null; Expr expr = report.AmountHandler.Expr; expr.Context = report; report.TotalHandler.Expr.Context = report; report.DisplayAmountHandler.Expr.Context = report; report.DisplayTotalHandler.Expr.Context = report; if (!forAccountsReport) { // Make sure only forecast postings which match are allowed through if (report.ForecastWhileHandler.Handled) { handler = new FilterPosts(handler, new Predicate(report.ForecastWhileHandler.Str(), report.WhatToKeep()), report); } // truncate_xacts cuts off a certain number of _xacts_ from being // displayed. It does not affect calculation. if (report.HeadHandler.Handled || report.TailHandler.Handled) { handler = new TruncateXacts(handler, report.HeadHandler.Handled ? Int32.Parse(report.HeadHandler.Value) : 0, report.TailHandler.Handled ? Int32.Parse(report.TailHandler.Value) : 0); } // display_filter_posts adds virtual posts to the list to account // for changes in value of commodities, which otherwise would affect // the running total unpredictably. handler = displayFilter = new DisplayFilterPosts(handler, report, report.RevaluedHandler.Handled && !report.NoRoundingHandler.Handled); // filter_posts will only pass through posts matching the // `display_predicate'. if (report.DisplayHandler.Handled) { displayPredicate = new Predicate(report.DisplayHandler.Str(), report.WhatToKeep()); handler = new FilterPosts(handler, displayPredicate, report); } } // changed_value_posts adds virtual posts to the list to account for changes // in market value of commodities, which otherwise would affect the running // total unpredictably. if (report.RevaluedHandler.Handled && (!forAccountsReport || report.UnrealizedHandler.Handled)) { handler = new ChangedValuePost(handler, report, forAccountsReport, report.UnrealizedHandler.Handled, displayFilter); } // calc_posts computes the running total. When this appears will determine, // for example, whether filtered posts are included or excluded from the // running total. handler = new CalcPosts(handler, expr, !forAccountsReport || (report.RevaluedHandler.Handled && report.UnrealizedHandler.Handled)); // filter_posts will only pass through posts matching the // `secondary_predicate'. if (report.OnlyHandler.Handled) { onlyPredicate = new Predicate(report.OnlyHandler.Str(), report.WhatToKeep()); handler = new FilterPosts(handler, onlyPredicate, report); } if (!forAccountsReport) { // sort_posts will sort all the posts it sees, based on the `sort_order' // value expression. if (report.SortHandler.Handled) { if (report.SortXactsHandler.Handled) { handler = new SortXacts(handler, new Expr(report.SortHandler.Str()), report); } else { handler = new SortPosts(handler, report.SortHandler.Str(), report); } } // collapse_posts causes xacts with multiple posts to appear as xacts // with a subtotaled post for each commodity used. if (report.CollapseHandler.Handled) { handler = new CollapsePosts(handler, report, expr, displayPredicate, onlyPredicate, report.CollapseIfZeroHandler.Handled); } // subtotal_posts combines all the posts it receives into one subtotal // xact, which has one post for each commodity in each account. // // period_posts is like subtotal_posts, but it subtotals according to time // periods rather than totalling everything. // // day_of_week_posts is like period_posts, except that it reports // all the posts that fall on each subsequent day of the week. if (report.EquityHandler.Handled) { handler = new PostsAsEquity(handler, report, expr); } else if (report.SubTotalHandler.Handled) { handler = new SubtotalPosts(handler, expr); } } if (report.DowHandler.Handled) { handler = new DayOfWeekPosts(handler, expr); } else if (report.ByPayeeHandler.Handled) { handler = new ByPayeePosts(handler, expr); } // interval_posts groups posts together based on a time period, such as // weekly or monthly. if (report.PeriodHandler.Handled) { handler = new IntervalPosts(handler, expr, new DateInterval(report.PeriodHandler.Str()), report.ExactHandler.Handled, report.EmptyHandler.Handled); } if (report.DateHandler.Handled) { handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_DATE, report.Session.Journal.Master, new Expr(report.DateHandler.Str()), report); } if (report.AccountHandler.Handled) { handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_ACCOUNT, report.Session.Journal.Master, new Expr(report.AccountHandler.Str()), report); } else if (report.PivotHandler.Handled) { string pivot = string.Format("\"{0}:\" + tag(\"{0}\")", report.PivotHandler.Str()); handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_ACCOUNT, report.Session.Journal.Master, new Expr(pivot), report); } if (report.PayeeHandler.Handled) { handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_PAYEE, report.Session.Journal.Master, new Expr(report.PayeeHandler.Str()), report); } // related_posts will pass along all posts related to the post received. If // the `related_all' handler is on, then all the xact's posts are passed; // meaning that if one post of an xact is to be printed, all the post for // that xact will be printed. if (report.RelatedHandler.Handled) { handler = new RelatedPosts(handler, report.RelatedAllHandler.Handled); } if (report.InjectHandler.Handled) { handler = new InjectPosts(handler, report.InjectHandler.Str(), report.Session.Journal.Master); } return(handler); }
public bool Equals(PostSearchResponse input) { if (input == null) { return(false); } return (( RelatedPosts == input.RelatedPosts || (RelatedPosts != null && RelatedPosts.SequenceEqual(input.RelatedPosts)) ) && ( Authors == input.Authors || (Authors != null && Authors.SequenceEqual(input.Authors)) ) && ( Groups == input.Groups || (Groups != null && Groups.SequenceEqual(input.Groups)) ) && ( SearchedTags == input.SearchedTags || (SearchedTags != null && SearchedTags.SequenceEqual(input.SearchedTags)) ) && ( Polls == input.Polls || (Polls != null && Polls.SequenceEqual(input.Polls)) ) && ( RecruitmentDetails == input.RecruitmentDetails || (RecruitmentDetails != null && RecruitmentDetails.SequenceEqual(input.RecruitmentDetails)) ) && ( AvailablePages == input.AvailablePages || (AvailablePages.Equals(input.AvailablePages)) ) && ( Results == input.Results || (Results != null && Results.SequenceEqual(input.Results)) ) && ( TotalResults == input.TotalResults || (TotalResults.Equals(input.TotalResults)) ) && ( HasMore == input.HasMore || (HasMore != null && HasMore.Equals(input.HasMore)) ) && ( Query == input.Query || (Query != null && Query.Equals(input.Query)) ) && ( ReplacementContinuationToken == input.ReplacementContinuationToken || (ReplacementContinuationToken != null && ReplacementContinuationToken.Equals(input.ReplacementContinuationToken)) ) && ( UseTotalResults == input.UseTotalResults || (UseTotalResults != null && UseTotalResults.Equals(input.UseTotalResults)) )); }
public void Update(PostSearchResponse?other) { if (other is null) { return; } if (!RelatedPosts.DeepEqualsList(other.RelatedPosts)) { RelatedPosts = other.RelatedPosts; OnPropertyChanged(nameof(RelatedPosts)); } if (!Authors.DeepEqualsList(other.Authors)) { Authors = other.Authors; OnPropertyChanged(nameof(Authors)); } if (!Groups.DeepEqualsList(other.Groups)) { Groups = other.Groups; OnPropertyChanged(nameof(Groups)); } if (!SearchedTags.DeepEqualsList(other.SearchedTags)) { SearchedTags = other.SearchedTags; OnPropertyChanged(nameof(SearchedTags)); } if (!Polls.DeepEqualsList(other.Polls)) { Polls = other.Polls; OnPropertyChanged(nameof(Polls)); } if (!RecruitmentDetails.DeepEqualsList(other.RecruitmentDetails)) { RecruitmentDetails = other.RecruitmentDetails; OnPropertyChanged(nameof(RecruitmentDetails)); } if (AvailablePages != other.AvailablePages) { AvailablePages = other.AvailablePages; OnPropertyChanged(nameof(AvailablePages)); } if (!Results.DeepEqualsList(other.Results)) { Results = other.Results; OnPropertyChanged(nameof(Results)); } if (TotalResults != other.TotalResults) { TotalResults = other.TotalResults; OnPropertyChanged(nameof(TotalResults)); } if (HasMore != other.HasMore) { HasMore = other.HasMore; OnPropertyChanged(nameof(HasMore)); } if (!Query.DeepEquals(other.Query)) { Query.Update(other.Query); OnPropertyChanged(nameof(Query)); } if (ReplacementContinuationToken != other.ReplacementContinuationToken) { ReplacementContinuationToken = other.ReplacementContinuationToken; OnPropertyChanged(nameof(ReplacementContinuationToken)); } if (UseTotalResults != other.UseTotalResults) { UseTotalResults = other.UseTotalResults; OnPropertyChanged(nameof(UseTotalResults)); } }