public static InfrastructureCategoryDbContext getInstance()
 {
     if (infrastructureCategoryDbContext == null)
     {
         infrastructureCategoryDbContext = new InfrastructureCategoryDbContext();
     }
     return(infrastructureCategoryDbContext);
 }
Esempio n. 2
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>());
            }
        }