private void LoadRelatedPost(MixCmsContext _context, IDbContextTransaction _transaction) { PostNavs = GetRelated(_context, _transaction); // Load other post ( != Id) and not actived (not in acticleNavs) var otherPosts = MixPosts.ReadListItemViewModel.Repository.GetModelListBy( m => m.Id != Id && m.Specificulture == Specificulture && !PostNavs.Any(n => n.DestinationId == m.Id) , "CreatedDateTime", 1, 10, 0, _context, _transaction); foreach (var item in otherPosts.Data.Items) { PostNavs.Add(new MixPostPosts.ReadViewModel() { SourceId = Id, Image = item.ImageUrl, DestinationId = item.Id, Description = item.Title }); } }
public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null) { if (Id == 0) { ExtraFields = MixService.GetConfig <string>("DefaultPostAttr"); } Cultures = LoadCultures(Specificulture, _context, _transaction); UrlAliases = GetAliases(_context, _transaction); if (!string.IsNullOrEmpty(this.Tags)) { ListTag = JArray.Parse(this.Tags); } // Parsing Extra Properties fields Columns = new List <ModuleFieldViewModel>(); JArray arrField = !string.IsNullOrEmpty(ExtraFields) ? JArray.Parse(ExtraFields) : new JArray(); foreach (var field in arrField) { ModuleFieldViewModel thisField = new ModuleFieldViewModel() { Name = MixCommonHelper.ParseJsonPropertyName(field["name"].ToString()), Title = field["title"]?.ToString(), Options = field["options"] != null ? field["options"].Value <JArray>() : new JArray(), Priority = field["priority"] != null ? field["priority"].Value <int>() : 0, DataType = (MixDataType)(int)field["dataType"], Width = field["width"] != null ? field["width"].Value <int>() : 3, IsUnique = field["isUnique"] != null ? field["isUnique"].Value <bool>() : true, IsRequired = field["isRequired"] != null ? field["isRequired"].Value <bool>() : true, IsDisplay = field["isDisplay"] != null ? field["isDisplay"].Value <bool>() : true, IsSelect = field["isSelect"] != null ? field["isSelect"].Value <bool>() : false, IsGroupBy = field["isGroupBy"] != null ? field["isGroupBy"].Value <bool>() : false, }; Columns.Add(thisField); } // Parsing Extra Properties value Properties = new List <ExtraProperty>(); if (!string.IsNullOrEmpty(ExtraProperties)) { JArray arr = JArray.Parse(ExtraProperties); foreach (JToken item in arr) { Properties.Add(item.ToObject <ExtraProperty>()); } } //Get Templates this.Templates = this.Templates ?? MixTemplates.UpdateViewModel.Repository.GetModelListBy( t => t.Theme.Id == ActivedTheme && t.FolderType == this.TemplateFolderType).Data; View = MixTemplates.UpdateViewModel.GetTemplateByPath(Template, Specificulture, MixTemplateFolders.Posts, _context, _transaction); this.Template = $"{this.View?.FileFolder}/{this.View?.FileName}"; var getPagePost = MixPagePosts.ReadViewModel.GetPagePostNavAsync(Id, Specificulture, _context, _transaction); if (getPagePost.IsSucceed) { this.Pages = getPagePost.Data; this.Pages.ForEach(c => { c.IsActived = MixPagePosts.ReadViewModel.Repository.CheckIsExists(n => n.PageId == c.PageId && n.PostId == Id, _context, _transaction); }); } var getModulePost = MixModulePosts.ReadViewModel.GetModulePostNavAsync(Id, Specificulture, _context, _transaction); if (getModulePost.IsSucceed) { this.Modules = getModulePost.Data; this.Modules.ForEach(c => { c.IsActived = MixModulePosts.ReadViewModel.Repository.CheckIsExists(n => n.ModuleId == c.ModuleId && n.PostId == Id, _context, _transaction); }); } var otherModules = MixModules.ReadListItemViewModel.Repository.GetModelListBy( m => (m.Type == (int)MixModuleType.Content || m.Type == (int)MixModuleType.ListPost) && m.Specificulture == Specificulture && !Modules.Any(n => n.ModuleId == m.Id && n.Specificulture == m.Specificulture) , "CreatedDateTime", Heart.Enums.DisplayDirection.Desc, null, 0, _context, _transaction); foreach (var item in otherModules.Data.Items) { Modules.Add(new MixModulePosts.ReadViewModel() { ModuleId = item.Id, Image = item.Image, PostId = Id, Description = Title }); } // Medias var getPostMedia = MixPostMedias.ReadViewModel.Repository.GetModelListBy(n => n.PostId == Id && n.Specificulture == Specificulture, _context, _transaction); if (getPostMedia.IsSucceed) { MediaNavs = getPostMedia.Data.OrderBy(p => p.Priority).ToList(); MediaNavs.ForEach(n => n.IsActived = true); } // Modules var getPostModule = MixPostModules.ReadViewModel.Repository.GetModelListBy( n => n.PostId == Id && n.Specificulture == Specificulture, _context, _transaction); if (getPostModule.IsSucceed) { ModuleNavs = getPostModule.Data.OrderBy(p => p.Priority).ToList(); foreach (var item in ModuleNavs) { item.IsActived = true; item.Module.LoadData(postId: Id, _context: _context, _transaction: _transaction); } } // Related Posts PostNavs = GetRelated(_context, _transaction); var otherPosts = MixPosts.ReadListItemViewModel.Repository.GetModelListBy( m => m.Id != Id && m.Specificulture == Specificulture && !PostNavs.Any(n => n.SourceId == Id) , "CreatedDateTime", Heart.Enums.DisplayDirection.Desc, 10, 0, _context, _transaction); foreach (var item in otherPosts.Data.Items) { PostNavs.Add(new MixPostPosts.ReadViewModel() { SourceId = Id, Image = item.ImageUrl, DestinationId = item.Id, Description = item.Title }); } }