コード例 #1
0
        public async Task <ActionResult> Detail(string title, long id)
        {
            var articleCategory = await _repository.GetRepository <ArticleCategory>().ReadAsync(o => o.ArticleId == id);

            if (articleCategory != null)
            {
                Category category = await _repository.GetRepository <Category>().ReadAsync(articleCategory.CategoryId);

                Category rootCategory = new SharedController().GetRootCategory(category);
                ViewBag.RootCategory = rootCategory;
                ViewBag.CategoryId   = articleCategory.CategoryId;
                ViewBag.Category     = category;
            }
            var article = _repository.GetRepository <Article>().Read(id);

            if (article.Status != 4)
            {
                return(RedirectToRoute("FrontEndHomeIndex"));
            }
            article.Views = article.Views + 1;
            try
            {
                await _repository.GetRepository <Article>().UpdateAsync(article, 0);
            }
            catch { }
            return(View(article));
        }
コード例 #2
0
        public async Task <ActionResult> Index(string categoryName, long categoryId, int p = 1)
        {
            Category category = await _repository.GetRepository <Category>().ReadAsync(categoryId);

            Category rootCategory = new SharedController().GetRootCategory(category);

            ViewBag.CategoryName = category.Name;
            ViewBag.RootCategory = rootCategory;
            ViewBag.CategoryId   = categoryId;
            ViewBag.Category     = category;

            if (category.CategoryId == null && category.DisplayType.HasValue &&
                (category.DisplayType.Value == 1 || category.DisplayType.Value == 3 || category.DisplayType.Value == 5))
            {
                if (category.DisplayType.Value == 5)
                {
                    List <Category> categories = new List <Category>();
                    if (category.Categories != null && category.Categories.Any())
                    {
                        foreach (var item in category.Categories.OrderBy(o => o.OrdinalNumber))
                        {
                            if (item.Categories != null && item.Categories.Any())
                            {
                                categories.AddRange(item.Categories.OrderBy(o => o.OrdinalNumber));
                            }
                        }
                    }
                    return(View("Category5", categories));
                }
                if (category.DisplayType.Value == 1)
                {
                    return(View("Category1"));//Không cần sanh sách bài viết
                }
                if (category.DisplayType.Value == 3)
                {
                    return(View("Category3"));//Không cần sanh sách bài viết
                }
            }

            int take     = 12;
            int skip     = (p - 1) * take;
            var articles = _repository.GetRepository <Article>().GetAll(o => o.Status == 4)
                           .Join(_repository.GetRepository <ArticleCategory>().GetAll(o => o.CategoryId == categoryId), b => b.Id, c => c.ArticleId, (b, c) => new { Article = b }).Select(x => x.Article)
                           .OrderByDescending(o => o.UpdateDate).ToList <Article>();

            if (articles == null || articles.AsQueryable().Count() == 0)
            {
                //var categoryIds = GetChildCategoryIds(rootCategory);
                var categoryIds = GetChildCategoryIds(category);
                articles = _repository.GetRepository <Article>().GetAll(o => o.Status == 4)
                           .Join(_repository.GetRepository <ArticleCategory>().GetAll(o => categoryIds.Contains(o.CategoryId)), b => b.Id, c => c.ArticleId, (b, c) => new { Article = b }).Select(x => x.Article)
                           .OrderByDescending(o => o.UpdateDate).ToList <Article>();
            }
            ViewBag.PagingInfo = new PagingInfo
            {
                CurrentPage  = p,
                ItemsPerPage = take,
                TotalItems   = articles.AsQueryable().Count()
            };
            articles = articles.OrderByDescending(o => o.UpdateDate).Skip(skip).Take(take).ToList();

            if (category.CategoryId == null && category.DisplayType.HasValue && category.DisplayType.Value == 2)
            {
                return(View("Category2", articles));
            }
            if (category.CategoryId == null && category.DisplayType.HasValue && category.DisplayType.Value == 4)
            {
                return(View("Category4", articles));
            }
            //return View(articles);//Bỏ cái này
            return(View("Category2", articles));
        }