Пример #1
0
        public ListArticleModel GetListByGroup(int groupId, int skip, int top, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryGetListByStatus{0}{1}{2}{3}", groupId, skip, top, LanguageId);

            var list = new ListArticleModel();

            if (!this.TryGetCache <ListArticleModel>(out list, key))
            {
                var query = (from p in web365db.tblGroup_Article_Map
                             where p.GroupID == groupId && p.tblArticle.tblTypeArticle.LanguageId == LanguageId && p.tblArticle.IsShow == isShow && p.tblArticle.IsDeleted == isDeleted
                             orderby p.ID descending
                             select new ArticleItem()
                {
                    ID = p.tblArticle.ID,
                    TypeID = p.tblArticle.TypeID,
                    Title = p.tblArticle.Title,
                    TitleAscii = p.tblArticle.TitleAscii,
                    SEOTitle = p.tblArticle.SEOTitle,
                    Summary = p.tblArticle.Summary,
                    Picture = new PictureItem()
                    {
                        ID = p.tblArticle.PictureID.HasValue ? p.tblArticle.tblPicture.ID : 0,
                        Name = p.tblArticle.PictureID.HasValue ? p.tblArticle.tblPicture.Name : string.Empty,
                        FileName = p.tblArticle.PictureID.HasValue ? p.tblArticle.tblPicture.FileName : string.Empty
                    },
                    ArticleType = new ArticleTypeItem()
                    {
                        ID = p.tblArticle.tblTypeArticle.ID,
                        Name = p.tblArticle.tblTypeArticle.Name,
                        NameAscii = p.tblArticle.tblTypeArticle.NameAscii,
                        ParentName = p.tblArticle.tblTypeArticle.tblTypeArticle2.Name,
                        ParentAscii = p.tblArticle.tblTypeArticle.tblTypeArticle2.NameAscii,
                    }
                });



                var group = (from p in web365db.tblGroupArticle
                             where p.ID == groupId
                             orderby p.ID descending
                             select p).FirstOrDefault();

                list.Group = new ArticleGroupItem()
                {
                    ID        = group.ID,
                    Name      = group.Name,
                    NameAscii = group.NameAscii
                };

                list.total = query.Count();

                list.List = query.Skip(skip).Take(top).ToList();

                this.SetCache(key, list, 10);
            }

            return(list);
        }
        public ActionResult Index(ListArticleModel model)
        {
            var pageSize = 5;

            //valid Keyword
            model.Keyword = string.IsNullOrEmpty(model.Keyword) ? "" : model.Keyword.Trim();
            bool?status = null;

            if (model.Status == ArticleStatusConst.Active)
            {
                status = true;
            }
            else if (model.Status == ArticleStatusConst.InActive)
            {
                status = false;
            }

            //Page
            var totalRecord = _articleService.FilterArticleCount(model.Keyword, status, model.CategoryId);
            var totalPage   = (totalRecord - 1) / pageSize + 1;

            if (model.Page < 1 || model.Page > totalPage)
            {
                return(RedirectToAction("Index", new { categoryId = model.CategoryId }));
            }

            model.PagerModel = new PaginationModels
            {
                PageNumber   = model.Page,
                PageSize     = pageSize,
                TotalRecords = totalRecord
            };

            model.ListCategories = _categoryService.GetActiveCategory();
            model.ListArticles   = _articleService.FilterArticle(model.Keyword, status, model.CategoryId, model.Page, pageSize).ToList();
            //var category = _categoryService.GetCategoryById(model.CategoryId);
            //if (category != null)
            //{
            //    model.CategoryTypeId = category.CategoryTypeId;
            //}
            model.ListStatus = new SelectList(new[]
            {
                new SelectListItem {
                    Text = "Hiển thị", Value = ArticleStatusConst.Active.ToString()
                },
                new SelectListItem {
                    Text = "Ẩn", Value = ArticleStatusConst.InActive.ToString()
                }
            }, "Value", "Text", model.Status);

            Title = "Danh sách bìa viết trợ giúp";
            ViewData["ToolbarTitle"] = Title;
            return(View(model));
        }
Пример #3
0
        public ListArticleModel GetListByType(int typeID, string nameAscii, int currentRecord, int pageSize, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryGetListByType{0}{1}{2}{3}", typeID, nameAscii, currentRecord, pageSize);

            var result = new ListArticleModel();

            if (!this.TryGetCache <ListArticleModel>(out result, key))
            {
                var paramTotal = new SqlParameter
                {
                    ParameterName = "Total",
                    SqlDbType     = SqlDbType.Int,
                    Direction     = ParameterDirection.Output
                };

                var query = web365db.Database.SqlQuery <ArticleMapItem>("exec [dbo].[PRC_GetListNewsByType] @TypeID, @TypeAscii, @CurrentRecord, @PageSize, @Total OUTPUT",
                                                                        new SqlParameter("TypeID", typeID),
                                                                        new SqlParameter("TypeAscii", nameAscii),
                                                                        new SqlParameter("CurrentRecord", currentRecord),
                                                                        new SqlParameter("PageSize", pageSize),
                                                                        paramTotal);

                result.List = query.Select(p => new ArticleItem()
                {
                    ID            = p.ID,
                    Title         = p.Title,
                    TitleAscii    = p.TitleAscii,
                    Summary       = p.Summary,
                    LinkReference = p.LinkReference,
                    DateCreated   = p.DateCreated,
                    Picture       = new PictureItem()
                    {
                        FileName = p.PictureURL
                    },
                    ArticleType = new ArticleTypeItem()
                    {
                        Name        = p.TypeName,
                        NameAscii   = p.TypeNameAscii,
                        ParentName  = p.TypeParentName,
                        ParentAscii = p.TypeParentNameAscii
                    }
                }).ToList();

                result.total = Convert.ToInt32(paramTotal.Value);

                this.SetCache(key, result, 10);
            }

            return(result);
        }
Пример #4
0
        public ListArticleModel GetListByTypeAndDetail(int typeId, int skip, int top, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryGetListByTypeAndDetail{0}{1}{2}", typeId, skip, top);

            var list = new ListArticleModel();

            if (!this.TryGetCache <ListArticleModel>(out list, key))
            {
                var query = (from p in web365db.tblArticle
                             where p.TypeID == typeId && p.IsShow == isShow && p.IsDeleted == isDeleted
                             orderby p.Number descending, p.ID ascending
                             select new ArticleItem()
                {
                    ID = p.ID,
                    TypeID = p.TypeID,
                    Title = p.Title,
                    TitleAscii = p.TitleAscii,
                    SEOTitle = p.SEOTitle,
                    Summary = p.Summary,
                    Detail = p.Detail,
                    Picture = new PictureItem()
                    {
                        ID = p.tblPicture != null ? p.tblPicture.ID : 0,
                        Name = p.tblPicture.Name,
                        FileName = p.tblPicture.FileName
                    },
                    ArticleType = new ArticleTypeItem()
                    {
                        ID = p.tblTypeArticle.ID,
                        Name = p.tblTypeArticle.Name,
                        NameAscii = p.tblTypeArticle.NameAscii,
                        ParentAscii = p.tblTypeArticle.tblTypeArticle2.NameAscii,
                        ParentName = p.tblTypeArticle.tblTypeArticle2.Name
                    }
                });

                list.total = query.Count();

                list.List = query.Skip(skip).Take(top).ToList();

                this.SetCache(key, list, 10);
            }

            return(list);
        }
Пример #5
0
        public ListArticleModel GetListByArrType(int[] arrType, int currentRecord, int pageSize, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryGetListByArrType{0}{1}{2}{3}", arrType, isShow, currentRecord, pageSize);

            var result = new ListArticleModel();

            if (!this.TryGetCache <ListArticleModel>(out result, key))
            {
                var query = from p in web365db.tblArticle
                            where arrType.Contains(p.TypeID.Value) && p.IsShow == isShow && p.IsDeleted == isDeleted
                            orderby p.Number descending, p.ID descending
                    select new ArticleItem()
                {
                    ID          = p.ID,
                    TypeID      = p.TypeID,
                    Title       = p.Title,
                    TitleAscii  = p.TitleAscii,
                    DateCreated = p.DateCreated.HasValue ? p.DateCreated.Value : DateTime.Now,
                    SEOTitle    = p.SEOTitle,
                    Summary     = p.Summary,
                    Tags        = p.Tags,
                    Picture     = new PictureItem()
                    {
                        FileName = p.tblPicture.FileName
                    },
                    ArticleType = new ArticleTypeItem()
                    {
                        ID             = p.tblTypeArticle.ID,
                        Name           = p.tblTypeArticle.Name,
                        NameAscii      = p.tblTypeArticle.NameAscii,
                        SEOTitle       = p.tblTypeArticle.SEOTitle,
                        SEODescription = p.tblTypeArticle.SEODescription,
                        SEOKeyword     = p.tblTypeArticle.SEOKeyword
                    }
                };

                result.total = query.Count();

                result.List = query.Skip(currentRecord).Take(pageSize).ToList();

                this.SetCache(key, result, 10);
            }

            return(result);
        }
Пример #6
0
        public ListArticleModel ArticleSeach(string[] keyword, string[] keywordAscii, int currentRecord, int top, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryArticleSeach{0}", keyword);

            var list = new ListArticleModel();

            if (!this.TryGetCache <ListArticleModel>(out list, key))
            {
                var query = (from p in web365db.tblArticle
                             where keyword.All(k => p.Title.ToLower().Contains(k)) || keyword.All(k => p.TitleAscii.Contains(k)) && p.tblTypeArticle.LanguageId == LanguageId && p.IsShow == isShow && p.IsDeleted == isDeleted
                             orderby p.ID descending
                             select new ArticleItem()
                {
                    ID = p.ID,
                    TypeID = p.TypeID,
                    Title = p.Title,
                    TitleAscii = p.TitleAscii,
                    SEOTitle = p.SEOTitle,
                    Summary = p.Summary,
                    Picture = new PictureItem()
                    {
                        ID = p.tblPicture.ID,
                        Name = p.tblPicture.Name,
                        FileName = p.tblPicture.FileName
                    },
                    ArticleType = new ArticleTypeItem()
                    {
                        ID = p.tblTypeArticle.ID,
                        Name = p.tblTypeArticle.Name,
                        NameAscii = p.tblTypeArticle.NameAscii,
                        ParentAscii = p.tblTypeArticle.tblTypeArticle2.NameAscii
                    }
                });

                list.total = query.Count();

                list.List = query.Skip(currentRecord).Take(top).ToList();

                this.SetCache(key, list, 10);
            }

            return(list);
        }
Пример #7
0
        public ActionResult Index(ArticleCondition Condition)
        {
            ListArticleModel model = new ListArticleModel();
            CategoryService service = new CategoryService();

            model.Condition = Condition;
            model.ListCategory = service.ListItem();
            model.ListCategory.Insert(0, new Entities.Item() { Text = "Chọn thư mục", Id = 0 });
            int total = 0;
            try
            {
                model.ListArticle = _service.List(Condition.CatId, Condition.SearchText, Condition.DisplayOnly, Condition.Page, Condition.PageSize, out total);
            }
            catch (Exception ex)
            {
                Logs.LogWrite(ex.ToString());
            }
            Paging(Condition.Page, total);

            return View(model);
        }