public List <IndexDiaryDto> GetDiariesDetails() { var details = new List <IndexDiaryDto>(); var diaries = db.Diary.Where(x => x.IsPublished).OrderByDescending(x => x.DateCreated).ToList(); foreach (var item in diaries) { var diary = new IndexDiaryDto { Name = item.Name, Code = generalHelper.RemoveSpecialCharsFromString(item.Name), ImageUrl = articleHelper.GetImageRelativePathByArticleId(item.Id) }; details.Add(diary); } return(details); }
public IndexMainDto GetIndexDetails() { var details = new IndexMainDto(); var articleList = db.Articles.Where(x => x.IsPublished).OrderByDescending(x => x.DateCreated).ToList(); var reviewList = new List <IndexReviewsDto>(); foreach ( var item in articleList.Where( x => x.CategoryId == articleHelper.GetCategoryByName("Recenzje").Id&& x.SubCategoryId == articleHelper.GetSubCategoryByName("Muzyka").Id).Take(6).ToList()) { var review = new IndexReviewsDto { Name = item.Name, Code = generalHelper.RemoveSpecialCharsFromString(item.Name), ImageUrl = articleHelper.GetImageRelativePathByArticleId(item.Id) }; reviewList.Add(review); } details.Reviews = reviewList; var postList = new List <ArticleDto>(); // Cut first 4 articles (they are on slider) var posts = articleList; for (var i = 0; i < 3; i++) { posts.RemoveAt(0); } foreach (var item in posts.Where( x => x.CategoryId != articleHelper.GetCategoryByName("Recenzje").Id)) { var article = new ArticleDto { Name = item.Name, CodedName = generalHelper.RemoveSpecialCharsFromString(item.Name), Body = item.IndexDescription, ImageUrl = articleHelper.GetImageRelativePathByArticleId(item.Id), Category = articleHelper.GetCategoryById(item.CategoryId).Name, Subcategory = articleHelper.GetSubCategoryById(item.SubCategoryId).Name }; postList.Add(article); } details.Articles = postList; details.Subcategories = details.Articles.Select(x => x.Subcategory).Distinct().ToList(); var diaries = db.Diary.Where(x => x.IsPublished).OrderByDescending(x => x.DateCreated).Take(7).ToList(); var diaryList = new List <IndexDiaryDto>(); foreach (var item in diaries) { var diary = new IndexDiaryDto { Name = item.Name, Code = generalHelper.RemoveSpecialCharsFromString(item.Name), ImageUrl = articleHelper.GetImageRelativePathByArticleId(item.Id) }; diaryList.Add(diary); } details.Diaries = diaryList; return(details); }