public LocationArchiveModel( string longDescription, string image, int id, string name, bool isEnglish, IPublishedContent content, IPublishedContent recommendationRepository, IContentService contentService, int page, bool published ) : base(content) { this.LongDescription = longDescription; this.Image = image; this.Name = name; this.Id = id; this.Page = page; this.Published = published; var recommendationContent = recommendationRepository .Children(x => x.IsVisible() && x.GetPropertyValue <int>(Constants.Recommendation.Properties.LOCATION) == this.Id); this.Total = recommendationContent.Count(); this.DisablePreviousButton = page == 1 ? true : false; this.DisableNextButton = page * pageSize > this.Total ? true : false; this.Recommendations = recommendationContent .Select(x => RecommendationFactory.Create(x, recommendationRepository, contentService, isEnglish, false)) .OrderByDescending(x => x.StartDate) .Skip((page - 1) * pageSize) .Take(pageSize) .ToList(); if (string.IsNullOrEmpty(this.Image)) { this.Image = this.Recommendations.FirstOrDefault().ImageUrl; } }
public RecommendationsModel( IPublishedContent content, bool isEnglish, bool isDetails, IContentService contentService) : base(content) { this.Recommendations = new List <RecommendationModel>(); var recommendationsRespository = content .FirstChild(x => x.DocumentTypeAlias == Constants.NodeAlias.RECOMMENDATIONS_REPOSITORY); if (recommendationsRespository == null) { return; } var recommendations = recommendationsRespository .Children(x => x.IsVisible() && DateTime.UtcNow.Date >= x.GetPropertyValue <DateTime>(Constants.Recommendation.Properties.START_DATE).GetFirstDayOfWeek(CultureInfo.CurrentCulture) && DateTime.UtcNow.Date <= x.GetPropertyValue <DateTime>(Constants.Recommendation.Properties.START_DATE).GetLastDayOfWeek(CultureInfo.CurrentCulture)); if (recommendations == null) { return; } UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current, content); IPublishedContent writer = helper.TypedContent(recommendationsRespository.GetPropertyValue <int>(Constants.Recommendations.Properties.EDITOR_OF_WEEK)); if (writer != null) { this.ThisWeeksEditorName = writer.GetPropertyValue <string>(Constants.Writer.Properties.NAME); this.ThisWeeksEditorId = writer.Id; this.ThisWeeksEdtiorPhoto = writer.GetCropUrl(Constants.Writer.Properties.IMAGE, Constants.Crop.MINITURE_CROP); } this.WeekDescription = recommendationsRespository.GetPropertyValue <string>(Constants.Recommendations.Properties.WEEK_DESCRIPTION); this.WeekDescriptionEN = recommendationsRespository.GetPropertyValue <string>(Constants.Recommendations.Properties.WEEK_DESCRIPTION_EN); this.Recommendations.AddRange(recommendations .Select(x => RecommendationFactory.Create(x, recommendationsRespository, contentService, isEnglish, isDetails))); this.Recommendations = this.Recommendations .OrderByDescending(x => x.IsGuestWriter) .ThenBy(x => x.StartDate) .Take(6) .ToList(); foreach (var recommendation in this.Recommendations) { if (this.Recommendations.IndexOf(recommendation) == 1) { recommendation.IsFirstRecommendation = true; } recommendation.MainWriter = this.MainWriterName; recommendation.MainWriterId = this.MainWriterId; recommendation.HaveGuestWriter = this.HaveGuestWriter; } }