Created
May 16, 2012 20:06
-
-
Save ryanlangton/2713537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BETTER STILL -- | |
private FaqTypeViewModel GetGeneralFaqType(IEnumerable<FaqModel> models) | |
{ | |
return new FaqTypeViewModel | |
{ | |
Name = "General", | |
Categories = GetCategoriesInModel(models) | |
}; | |
} | |
private IEnumerable<FaqCategoryViewModel> GetCategoriesInModel(IEnumerable<FaqModel> models) | |
{ | |
foreach (var category in faqRepository.GetAllCategories()) | |
if (models.Any(x => x.CategoryKey == category.Key)) | |
yield return BuildCategoryViewModel(category, models.Where(x => x.CategoryKey == category.Key)); | |
} | |
========================================================= | |
OLD CODE -- | |
private FaqTypeViewModel GetGeneralFaqType(IEnumerable<FaqModel> models) | |
{ | |
var categories = new List<FaqCategoryViewModel>(); | |
foreach (var category in faqRepository.GetAllCategories()) | |
if(models.Any(x => x.CategoryKey == category.Key)) | |
categories.Add(BuildCategoryViewModel(category, models.Where(x => x.CategoryKey == category.Key))); | |
return new FaqTypeViewModel | |
{ | |
Name = "General", | |
Categories = categories | |
} | |
} | |
==== RYAN'S HORRIBLE CODE ==== | |
private FaqTypeViewModel GetGeneralFaqType(IEnumerable<FaqModel> models) | |
{ | |
var categories = new List<FaqCategoryViewModel>(); | |
var type = new FaqTypeViewModel | |
{ | |
Name = "General" | |
}; | |
var categoryModels = faqRepository.GetAllCategories(); | |
foreach (var category in categoryModels) | |
{ | |
var faqs = models.Where(x => x.CategoryKey == category.Key); | |
if(faqs.Count() > 0) | |
{ | |
categories.Add(BuildCategoryViewModel(category, faqs)); | |
} | |
} | |
type.Categories = categories; | |
return type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment