示例#1
0
        public ShowArticleViewModel(Article article)
        {
            ConvertDate convert = new ConvertDate();

            Id            = article.Id;
            Title         = article.Title;
            Date          = convert.ConvertMiladiToShamsi(article.PublishDate.Value, "yyyy/MM/dd");
            Content       = article.Content;
            CategoryTitle = article.Category.Title;
            View          = article.View;
            TimeToRead    = article.TimeToRead.Value;
            Image         = "/Files/" + article.Image;
            if (string.IsNullOrEmpty(article.Tags))
            {
                Tags = new List <string>();
            }
            else
            {
                Tags = article.Tags.Split(',').ToList();
                for (int i = 0; i < Tags.Count; i++)
                {
                    Tags[i] = Tags[i].Replace(' ', '_');
                }
            }
        }
示例#2
0
        public async Task <IEnumerable <TopArticleViewModel> > GetTopArticlesAsync()
        {
            var articles = await _articleRep.FindByConditionAsync(n => n.IsPublish, n => n.OrderByDescending(n => n.View));

            articles = articles.Take(5);
            List <TopArticleViewModel> articleViewModels = new List <TopArticleViewModel>();

            foreach (var item in articles)
            {
                articleViewModels.Add(new TopArticleViewModel
                {
                    Description = item.Description,
                    Title       = item.Title,
                    View        = item.View,
                    Image       = item.Image,
                    PublishDate = _convert.ConvertMiladiToShamsi(item.PublishDate.Value, "yyyy/MM/dd"),
                });
            }
            return(articleViewModels);
        }
示例#3
0
        public async Task <IActionResult> Index(int row = 5, int index = 1)
        {
            int count    = 0;
            var articles = await _articleRep.FindByConditionAsync(n => n.IsPublish, n => n.OrderByDescending(x => x.PublishDate));

            articles = Pagination.GetData <Article>(articles, ref count, row, index);
            articles = await _articleRep.GetAllReferencePropertyAsync(articles, n => n.Category);

            var model = articles.Select(n => new TopArticleViewModel
            {
                CategoryTitle = n.Category.Title,
                Description   = n.Description,
                Image         = n.Image,
                PublishDate   = _convert.ConvertMiladiToShamsi(n.PublishDate.Value, "yyyy/MM/dd"),
                TimeToRead    = n.TimeToRead.Value,
                Title         = n.Title,
                View          = n.View
            });

            count = count % row == 0 ? count / row : (count / row) + 1;
            ViewBag.Pagination = new Pagination(count, index, row, "/articles", "&raquo;", "&laquo");
            return(View(model));
        }