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 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)); }