private void LoadSubModules(MixCmsContext _context, IDbContextTransaction _transaction)
        {
            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);
                }
            }
            var otherModuleNavs = MixModules.ReadMvcViewModel.Repository.GetModelListBy(
                m => (m.Type == (int)MixEnums.MixModuleType.SubPost) && m.Specificulture == Specificulture &&
                !ModuleNavs.Any(n => n.ModuleId == m.Id), "CreatedDateTime", 1, null, 0, _context, _transaction);

            foreach (var item in otherModuleNavs.Data.Items)
            {
                item.LoadData(postId: Id, _context: _context, _transaction: _transaction);
                ModuleNavs.Add(new MixPostModules.ReadViewModel()
                {
                    ModuleId    = item.Id,
                    Image       = item.Image,
                    PostId      = Id,
                    Description = item.Title,
                    Module      = item
                });
            }
        }
        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            Cultures = LoadCultures(Specificulture, _context, _transaction);

            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }
            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.Name == ActivedTheme && t.FolderType == this.TemplateFolderType).Data;
            View = MixTemplates.UpdateViewModel.GetTemplateByPath(Template, Specificulture, MixEnums.EnumTemplateFolder.Articles, _context, _transaction);

            this.Template = CommonHelper.GetFullPath(new string[]
            {
                this.View?.FileFolder
                , this.View?.FileName
            });

            var getPageArticle = MixPageArticles.ReadViewModel.GetPageArticleNavAsync(Id, Specificulture, _context, _transaction);

            if (getPageArticle.IsSucceed)
            {
                this.Pages = getPageArticle.Data;
                this.Pages.ForEach(c =>
                {
                    c.IsActived = MixPageArticles.ReadViewModel.Repository.CheckIsExists(n => n.CategoryId == c.CategoryId && n.ArticleId == Id, _context, _transaction);
                });
            }

            var getModuleArticle = MixModuleArticles.ReadViewModel.GetModuleArticleNavAsync(Id, Specificulture, _context, _transaction);

            if (getModuleArticle.IsSucceed)
            {
                this.Modules = getModuleArticle.Data;
                this.Modules.ForEach(c =>
                {
                    c.IsActived = MixModuleArticles.ReadViewModel.Repository.CheckIsExists(n => n.ModuleId == c.ModuleId && n.ArticleId == Id, _context, _transaction);
                });
            }
            var otherModules = MixModules.ReadListItemViewModel.Repository.GetModelListBy(
                m => (m.Type == (int)MixEnums.MixModuleType.Content || m.Type == (int)MixEnums.MixModuleType.ListArticle) &&
                m.Specificulture == Specificulture &&
                !Modules.Any(n => n.ModuleId == m.Id && n.Specificulture == m.Specificulture)
                , "CreatedDateTime", 1, null, 0, _context, _transaction);

            foreach (var item in otherModules.Data.Items)
            {
                Modules.Add(new MixModuleArticles.ReadViewModel()
                {
                    ModuleId    = item.Id,
                    Image       = item.Image,
                    ArticleId   = Id,
                    Description = item.Title
                });
            }

            // Medias
            var getArticleMedia = MixArticleMedias.ReadViewModel.Repository.GetModelListBy(n => n.ArticleId == Id && n.Specificulture == Specificulture, _context, _transaction);

            if (getArticleMedia.IsSucceed)
            {
                MediaNavs = getArticleMedia.Data.OrderBy(p => p.Priority).ToList();
                MediaNavs.ForEach(n => n.IsActived = true);
            }
            // var otherMedias = MixMedias.UpdateViewModel.Repository.GetModelListBy(m => !MediaNavs.Any(n => n.MediaId == m.Id), "CreatedDateTime", 1, 10, 0, _context, _transaction);
            // foreach (var item in otherMedias.Data.Items)
            // {
            //     MediaNavs.Add(new MixArticleMedias.ReadViewModel()
            //     {
            //         MediaId = item.Id,
            //         Image = item.FullPath,
            //         ArticleId = Id,
            //         Description = item.Title
            //     });
            // }
            // Modules
            var getArticleModule = MixArticleModules.ReadViewModel.Repository.GetModelListBy(
                n => n.ArticleId == Id && n.Specificulture == Specificulture, _context, _transaction);

            if (getArticleModule.IsSucceed)
            {
                ModuleNavs = getArticleModule.Data.OrderBy(p => p.Priority).ToList();
                foreach (var item in ModuleNavs)
                {
                    item.IsActived = true;
                    item.Module.LoadData(articleId: Id, _context: _context, _transaction: _transaction);
                }
            }
            var otherModuleNavs = MixModules.ReadMvcViewModel.Repository.GetModelListBy(
                m => (m.Type == (int)MixEnums.MixModuleType.SubArticle) && m.Specificulture == Specificulture &&
                !ModuleNavs.Any(n => n.ModuleId == m.Id), "CreatedDateTime", 1, null, 0, _context, _transaction);

            foreach (var item in otherModuleNavs.Data.Items)
            {
                item.LoadData(articleId: Id, _context: _context, _transaction: _transaction);
                ModuleNavs.Add(new MixArticleModules.ReadViewModel()
                {
                    ModuleId    = item.Id,
                    Image       = item.Image,
                    ArticleId   = Id,
                    Description = item.Title,
                    Module      = item
                });
            }

            // Related Articles
            ArticleNavs = GetRelated(_context, _transaction);
            var otherArticles = MixArticles.ReadListItemViewModel.Repository.GetModelListBy(m => !ArticleNavs.Any(n => n.SourceId == m.Id), "CreatedDateTime", 1, 10, 0, _context, _transaction);

            foreach (var item in otherArticles.Data.Items)
            {
                ArticleNavs.Add(new MixArticleArticles.ReadViewModel()
                {
                    SourceId      = Id,
                    Image         = item.ImageUrl,
                    DestinationId = item.Id,
                    Description   = item.Title
                });
            }
        }
Beispiel #3
0
        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       = CommonHelper.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, MixEnums.EnumTemplateFolder.Posts, _context, _transaction);

            this.Template = CommonHelper.GetFullPath(new string[]
            {
                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)MixEnums.MixModuleType.Content || m.Type == (int)MixEnums.MixModuleType.ListPost) &&
                m.Specificulture == Specificulture &&
                !Modules.Any(n => n.ModuleId == m.Id && n.Specificulture == m.Specificulture)
                , "CreatedDateTime", 1, 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);
                }
            }
            var otherModuleNavs = MixModules.ReadMvcViewModel.Repository.GetModelListBy(
                m => (m.Type == (int)MixEnums.MixModuleType.SubPost) && m.Specificulture == Specificulture &&
                !ModuleNavs.Any(n => n.ModuleId == m.Id), "CreatedDateTime", 1, null, 0, _context, _transaction);

            foreach (var item in otherModuleNavs.Data.Items)
            {
                item.LoadData(postId: Id, _context: _context, _transaction: _transaction);
                ModuleNavs.Add(new MixPostModules.ReadViewModel()
                {
                    ModuleId    = item.Id,
                    Image       = item.Image,
                    PostId      = Id,
                    Description = item.Title,
                    Module      = item
                });
            }

            // 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", 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
                });
            }
        }