public IEnumerable<SubcategoryModel> GetSubcategories(string category) { return this.ExecuteOperationOrHandleExceptions(() => { var context = new Top10AppDbContext(); var categoriesEntities = context.Categories; IEnumerable<CategoryModel> currentCategory = (from categoryEntity in categoriesEntities where categoryEntity.Name == category select new CategoryModel() { id = categoryEntity.Id, name = categoryEntity.Name, subcategories = (from subcategoryEntity in categoryEntity.Subcategories select new SubcategoryModel() { id = subcategoryEntity.Id, name = subcategoryEntity.Name }) }); return currentCategory.FirstOrDefault().subcategories; }); }
public IEnumerable<CategoryModel> GetAll() { return this.ExecuteOperationOrHandleExceptions(() => { var context = new Top10AppDbContext(); var categoriesEntities = context.Categories; var categories = (from categoryEntity in categoriesEntities select new CategoryModel() { id = categoryEntity.Id, name = categoryEntity.Name, subcategories = (from subcategoryEntity in categoryEntity.Subcategories select new SubcategoryModel() { id = subcategoryEntity.Id, name = subcategoryEntity.Name, subcategories = (from storyEntity in subcategoryEntity.Stories select new StoryModel() { id = storyEntity.Id, name = storyEntity.Name, subcategories = (from articleEntity in storyEntity.Articles select new ArticleModel() { id = articleEntity.Id, name = articleEntity.Name, info = articleEntity.Info, image = articleEntity.Image }) }) }) }); return categories; }); }