Esempio n. 1
0
        // initializations


        #endregion



        // methods

        #region "Query"

        public List <ArticlePublished> findPublishedArticlesGroupByBaseVersion(string lang = "en", string role = null)
        {
            using (var db = new BaseDbContext())
            {
                if (SessionPersister.account != null && SessionPersister.account.isRoleSuperadmin())
                {
                    return(db.articlePublishedDb
                           .GroupBy(acc => acc.BaseArticleID)
                           .Select(u => u.Where(acc => acc.Lang == lang
                                                ).OrderByDescending(acc => acc.Version)
                                   .FirstOrDefault())
                           .OrderByDescending(acc => acc.datePublished)
                           .Include(acc => acc.createdByAccount)
                           .Include(acc => acc.approvedByAccount)
                           .Include(acc => acc.publishedByAccount)
                           .Include(acc => acc.category)
                           .ToList());
                }

                else if (SessionPersister.account != null)
                {
                    var categories = SessionPersister.account.Group.getAccessibleCategoryListInt();

                    return(db.articlePublishedDb
                           .GroupBy(acc => acc.BaseArticleID)
                           .Select(u => u.Where(acc => acc.Lang == lang
                                                ).OrderByDescending(acc => acc.Version)
                                   .FirstOrDefault())
                           .Where(acc => categories.Contains(acc.categoryID ?? 0))
                           .OrderByDescending(acc => acc.datePublished)
                           .Include(acc => acc.createdByAccount)
                           .Include(acc => acc.approvedByAccount)
                           .Include(acc => acc.publishedByAccount)
                           .Include(acc => acc.category)
                           .ToList());
                }


                else if (role != null)
                {
                    var categories = InfrastructureCategoryDbContext.getInstance().findAllEnabledCategorysByPermission(role);

                    List <int> listInt = new List <int>();

                    foreach (var cat in categories)
                    {
                        listInt.Add(cat.ItemID);
                    }

                    return(db.articlePublishedDb
                           .GroupBy(acc => acc.BaseArticleID)
                           .Select(u => u.Where(acc => acc.Lang == lang
                                                ).OrderByDescending(acc => acc.Version)
                                   .FirstOrDefault())
                           .Where(acc => listInt.Contains(acc.categoryID ?? 0))
                           .OrderByDescending(acc => acc.datePublished)
                           .Include(acc => acc.createdByAccount)
                           .Include(acc => acc.approvedByAccount)
                           .Include(acc => acc.publishedByAccount)
                           .Include(acc => acc.category)
                           .ToList());
                }

                return(new List <ArticlePublished>());
            }
        }
        public string edit(Category category)
        {
            using (var db = new BaseDbContext())
            {
                if (category.parentItemID == category.ItemID)
                {
                    return("Parent Item ID should not be the same as its own item ID.");
                }

                var _category = findCategoryByIDNoTracking(category.ItemID);
                category.created_at = _category.created_at;

                var local = db.infrastructureCategoryDb
                            .Local
                            .FirstOrDefault(f => f.ItemID == category.ItemID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }


                List <string> modified_fields = new List <string>();

                if (_category.url != category.url)
                {
                    modified_fields.Add("url");
                }
                if (_category.name_en != category.name_en)
                {
                    modified_fields.Add("name_en");
                }
                if (_category.name_zh != category.name_zh)
                {
                    modified_fields.Add("name_zh");
                }
                if (_category.name_cn != category.name_cn)
                {
                    modified_fields.Add("name_cn");
                }
                if (_category.iconPath != category.iconPath)
                {
                    modified_fields.Add("iconPath");
                }
                if (_category.thumbPath != category.thumbPath)
                {
                    modified_fields.Add("thumbPath");
                }
                if (_category.imagePath != category.imagePath)
                {
                    modified_fields.Add("imagePath");
                }
                if (_category.remarks != category.remarks)
                {
                    modified_fields.Add("remarks");
                }
                if (_category.pageClassName != category.pageClassName)
                {
                    modified_fields.Add("pageClassName");
                }
                if (_category.isEnabled != category.isEnabled)
                {
                    modified_fields.Add("isEnabled");
                }
                if (_category.isContentPage != category.isContentPage)
                {
                    modified_fields.Add("isContentPage");
                }
                if (_category.isArticleList != category.isArticleList)
                {
                    modified_fields.Add("isArticleList");
                }
                if (_category.isVisibleToVisitorOnly != category.isVisibleToVisitorOnly)
                {
                    modified_fields.Add("isVisibleToVisitorOnly");
                }
                if (_category.isVisibleToMembersOnly != category.isVisibleToMembersOnly)
                {
                    modified_fields.Add("isVisibleToMembersOnly");
                }
                if (_category.isVisibleToTradingOnly != category.isVisibleToTradingOnly)
                {
                    modified_fields.Add("isVisibleToTradingOnly");
                }
                if (_category.isHeaderMenu != category.isHeaderMenu)
                {
                    modified_fields.Add("isHeaderMenu");
                }
                if (_category.isHeaderMenuRight != category.isHeaderMenuRight)
                {
                    modified_fields.Add("isHeaderMenuRight");
                }
                if (_category.isFooterMenu != category.isFooterMenu)
                {
                    modified_fields.Add("isFooterMenu");
                }
                if (_category.isBottomMenu != category.isBottomMenu)
                {
                    modified_fields.Add("isBottomMenu");
                }
                if (_category.isShortcut != category.isShortcut)
                {
                    modified_fields.Add("isShortcut");
                }
                if (_category.isJumbotron != category.isJumbotron)
                {
                    modified_fields.Add("isJumbotron");
                }
                if (_category.isBanner != category.isBanner)
                {
                    modified_fields.Add("isBanner");
                }
                if (_category.pageShouldShowTopbarmenu != category.pageShouldShowTopbarmenu)
                {
                    modified_fields.Add("pageShouldShowTopbarmenu");
                }
                if (_category.pageShouldHideTopTitle != category.pageShouldHideTopTitle)
                {
                    modified_fields.Add("pageShouldHideTopTitle");
                }
                if (_category.pageShouldHideFromHorizontalMenu != category.pageShouldHideFromHorizontalMenu)
                {
                    modified_fields.Add("pageShouldHideFromHorizontalMenu");
                }
                if (_category.isUseNewsArticleDetailsTemplate != category.isUseNewsArticleDetailsTemplate)
                {
                    modified_fields.Add("isUseNewsArticleDetailsTemplate");
                }



                if (category.parentItemID < 0)
                {
                    category.parentItemID = null;
                }

                if (category.iconPath != null && category.iconPath.Equals("____EMPTY"))
                {
                    category.iconPath = null;
                }
                else if (category.iconPath == null)
                {
                    category.iconPath = _category.iconPath;
                }

                if (category.thumbPath != null && category.thumbPath.Equals("____EMPTY"))
                {
                    category.thumbPath = null;
                }
                else if (category.thumbPath == null)
                {
                    category.thumbPath = _category.thumbPath;
                }

                if (category.imagePath != null && category.imagePath.Equals("____EMPTY"))
                {
                    category.imagePath = null;
                }
                else if (category.imagePath == null)
                {
                    category.imagePath = _category.imagePath;
                }

                AuditLogDbContext.getInstance().createAuditLogCategoryAction(category, AuditLogDbContext.ACTION_EDIT, modified_fields);

                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(null);
            }
        }
Esempio n. 3
0
        // ARTICLE PUBLISHER ONLY

        #region "Publish / Unpublish"

        public string tryPublishArticle(Article article, bool allLocales)
        {
            using (var db = new BaseDbContext())
            {
                var _article = article;
                if (_article == null)
                {
                    return("Item not found");
                }
                if (!_article.isApproved)
                {
                    return("Item not approved");
                }

                var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);
                if (error != null)
                {
                    return(error);
                }

                deletePublishedArticlesByBaseArticle(article);
                addArticleToPublished(article);

                var local = db.articleDb
                            .Local
                            .FirstOrDefault(f => f.BaseArticleID == _article.BaseArticleID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }
            }

            using (var db = new BaseDbContext())
            {
                var _article = article;
                db.Entry(_article).State  = EntityState.Modified;
                _article.isPublished      = true;
                _article.datePublished    = DateTimeExtensions.GetServerTime();
                _article.datePublishStart = article.datePublishStart;
                _article.datePublishEnd   = article.datePublishEnd;
                _article.publishedBy      = SessionPersister.account.AccountID;

                if (allLocales)
                {
                    var _localeArticles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State  = EntityState.Modified;
                        _a.isPublished      = true;
                        _a.datePublished    = DateTimeExtensions.GetServerTime();
                        _a.datePublishStart = article.datePublishStart;
                        _a.datePublishEnd   = article.datePublishEnd;
                        _a.publishedBy      = SessionPersister.account.AccountID;
                    }
                }


                var allArticles = ArticleDbContext.getInstance().findArticlesGroupByBaseVersionApproved(_article.BaseArticleID, "en", db);
                foreach (Article a in allArticles)
                {
                    if (_article.ArticleID == a.ArticleID)
                    {
                        continue;
                    }

                    db.Entry(a).State = EntityState.Modified;
                    a.isPublished     = false;
                    a.datePublished   = null;
                    a.publishedBy     = null;

                    if (allLocales)
                    {
                        var _localeArticles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(a, a.Lang, db);
                        foreach (var _a in _localeArticles)
                        {
                            db.Entry(_a).State = EntityState.Modified;
                            _a.isPublished     = false;
                            _a.datePublished   = null;
                            _a.publishedBy     = null;
                        }
                    }
                }



                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_PUBLISH);

                return(null);
            }
        }