Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.