public CompositeSubcategoryViewModel GetNewSubcategoryViewModelWithCategories() { CompositeSubcategoryViewModel model = new CompositeSubcategoryViewModel(); using (var context = new WebShopMVCContext()) { model.Categories = context.Categories.Select(c => new CategoryViewModel { CategoryName = c.CategoryName, CategoryId = c.CategoryId }).ToList(); } return model; }
public CompositeSubcategoryViewModel GetModelById(int id) { CompositeSubcategoryViewModel model; using (var context = new WebShopMVCContext()) { var subcategory = context.Subcategories.Find(id); model = new CompositeSubcategoryViewModel { CategoryId = subcategory.CategoryId, SubcategoryId = subcategory.SubcategoryId, SubcategoryName = subcategory.SubcategoryName, Categories = context.Categories.Select(c => new CategoryViewModel { CategoryName = c.CategoryName, CategoryId = c.CategoryId }).ToList() }; } return model; }