public BlogDto GetBlogArticle(int?categoryId = null) { var blogDto = new BlogDto(); var repos = new ArticlesRepository(_context, new LogsRepository(_context)); var blogs = new List <BlogViewModel>(); if (categoryId == null) { blogs = repos.GetArticles().Select(s => new BlogViewModel(s, _currentLang)).ToList(); } else { var category = repos.GetCategory(categoryId.Value); if (category != null) { //ViewBag.BreadCrumb = category.Title; blogs = repos.GetArticlesByCategory(categoryId.Value).Select(s => new BlogViewModel(s, _currentLang)).ToList(); } } var categories = _context.ArticleCategories.Where(w => !w.IsDeleted) .Select(s => new BlogCategoryModel { Id = s.Id, Title = _currentLang == (int)Language.Farsi ? s.Title : s.EnglishTitle }).ToList(); blogDto.Blogs.AddRange(blogs); blogDto.Categories.AddRange(categories); blogDto.RecentBlogs = repos.GetArticles().Select(s => new BlogViewModel(s, _currentLang)).ToList(); return(blogDto); }
public ActionResult SearchArticle(string searchString = null, int pageNumber = 1) { var take = 3; var articles = new List <Article>(); var articleListVm = new List <ArticleListViewModel>(); if (!string.IsNullOrEmpty(searchString)) { articles = _repo.GetArticles().Where(a => a.Title.ToLower().Trim().Contains(searchString.ToLower().Trim()) || a.ShortDescription.ToLower() .Trim().Contains(searchString.ToLower().Trim())) .ToList(); } else { articles = _repo.GetArticles(); } int pageCount = articles.Count / take + 1; ViewBag.SearchString = searchString; ViewBag.PageCount = pageCount; ViewBag.CurrentPage = pageNumber; var skip = (pageNumber - 1) * take; articles = articles.Skip(skip).Take(take).ToList(); foreach (var item in articles) { var vm = new ArticleListViewModel(item); var commentCount = _repo.GetArticleComments(item.Id).Count; vm.CommentCount = commentCount; articleListVm.Add(vm); } #region BreadCrumb var breadCrumbVm = new List <BreadCrumbViewModel>(); breadCrumbVm.Add(new BreadCrumbViewModel() { Title = "بلاگ", Href = "/Blog" }); if (!string.IsNullOrEmpty(searchString)) { breadCrumbVm.Add(new BreadCrumbViewModel() { Title = $"جستجو : {searchString}", Href = "#" }); } ViewBag.BreadCrumb = breadCrumbVm; #endregion return(View(articleListVm)); }
// GET: Admin/Articles public ActionResult Index() { var articles = _repo.GetArticles(); var articlesListVm = new List <ArticleInfoViewModel>(); foreach (var article in articles) { var articleVm = new ArticleInfoViewModel(article); articlesListVm.Add(articleVm); } return(View(articlesListVm)); }
public IActionResult Index(SearchModel model) { var searchString = model.SearchString; if (String.IsNullOrEmpty(model.SearchString)) { model.SearchResult = new Article[0]; } else { model.SearchResult = _articlesRepository.GetArticles(model.SearchString).ToList(); } return(View(model)); }
public IActionResult Index(SearchModel model) { var searchString = model.SearchString; if (String.IsNullOrEmpty(model.SearchString)) { model.SearchResult = new Article[0]; } else { model.SearchResult = _articlesRepository.GetArticles().Where(p => CultureInfo.CurrentCulture.CompareInfo.IndexOf (p.Word, searchString, CompareOptions.IgnoreCase) >= 0).ToList(); } return(View(model)); }
public BlogDetailDto GetBlogArticleDetail(int id) { var repos = new ArticlesRepository(_context, new LogsRepository(_context)); var detail = repos.Get(id); var blogDto = new BlogDetailDto(detail, _currentLang); var categories = _context.ArticleCategories.Where(w => !w.IsDeleted).Select(s => new BlogCategoryModel { Id = s.Id, Title = _currentLang == (int)Language.Farsi ? s.Title : s.EnglishTitle }).ToList(); blogDto.Categories.AddRange(categories); blogDto.RecentBlogs = repos.GetArticles().Select(s => new BlogViewModel(s, _currentLang)).ToList(); return(blogDto); }
public ActionResult Index(int?id = null, string searchString = null) { ViewBag.BlogImage = _contentRepo.GetStaticContentDetail((int)StaticContents.BlogImage).Image; var articles = new List <Article>(); if (id == null) { articles = _articlesRepo.GetArticles(); if (!string.IsNullOrEmpty(searchString)) { ViewBag.BreadCrumb = $"جستجو {searchString}"; articles = articles.Where(a => a.Title.ToLower().Trim().Contains(searchString.ToLower().Trim()) || a.ShortDescription.ToLower() .Trim().Contains(searchString.ToLower().Trim()) || a.Description.ToLower() .Trim().Contains(searchString.ToLower().Trim()) || a.ArticleTags.Any(t => t.Title.ToLower().Trim().Contains(searchString.ToLower().Trim()))).ToList(); } } else { var category = _articlesRepo.GetCategory(id.Value); if (category != null) { ViewBag.BreadCrumb = category.Title; articles = _articlesRepo.GetArticlesByCategory(id.Value); } } var articlelistVm = new List <ArticleListViewModel>(); foreach (var item in articles) { var vm = new ArticleListViewModel(item); vm.Role = _articlesRepo.GetAuthorRole(item.UserId); articlelistVm.Add(vm); } return(View(articlelistVm)); }
// GET: Main public ActionResult Index() { var repo = new ArticlesRepository(); ArticleViewModel articlesViewModel = repo.GetArticles(); ArticleViewModel articlesPreviewModel = new ArticleViewModel { ArticleItems = articlesViewModel.ArticleItems.Select(article => new ArticleItem { ArticleId = article.ArticleId, ArticleTitle = article.ArticleTitle, Author = article.Author, Time = article.Time, ArticleBody = article.ArticleBody.Substring(0, article.ArticleBody.IndexOf("/", StringComparison.Ordinal) + 2) } ).ToList() }; var repoPoll = new PublicPollRepository(); articlesPreviewModel.PublicPolls = repoPoll.GetPublicPoll(); return(View(articlesPreviewModel)); }
public IHttpActionResult GetValues() { var articles = ArticlesRepository.GetArticles(); return(Ok(articles)); }