// GET: ComponentTypes/Details/5
        public async Task <IActionResult> Details(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var viewModel = new ComponentTypeIndexData();

            viewModel.ComponentTypes = await _context.ComponentTypes
                                       .Include(ct => ct.ComponentTypeCategories)
                                       .ThenInclude(ct => ct.Category)
                                       .AsNoTracking()
                                       .ToListAsync();

            ComponentType componentType = viewModel.ComponentTypes.Where(
                ct => ct.ComponentTypeID == id.Value).Single();

            viewModel.Categories = componentType.ComponentTypeCategories
                                   .Select(s => s.Category);

            if (componentType == null)
            {
                return(NotFound());
            }

            return(View(componentType));
        }
Пример #2
0
        // GET: Categories
        public ActionResult Index()
        {
            var viewModel = new ComponentTypeIndexData();

            viewModel.Categories = db.Categories.Include(i => i.ComponentTypes);

            return(View(viewModel));
        }
        public async Task <IActionResult> Index()
        {
            PopulateCategoriesList();

            ViewData["CategoryName"] = "all";

            var viewModel = new ComponentTypeIndexData();

            viewModel.ComponentTypes = await _context.ComponentTypes
                                       .Include(ct => ct.ComponentTypeCategories)
                                       .ThenInclude(ct => ct.Category)
                                       .AsNoTracking()
                                       .ToListAsync();

            return(View("Selected", viewModel));
        }
        public async Task <IActionResult> Selected(int?id)
        {
            PopulateCategoriesList();

            if (id == null)
            {
                //show all component types
                return(View(await _context.ComponentTypes.ToListAsync()));
            }

            ViewData["CategoryID"] = id;

            var viewModel = new ComponentTypeIndexData();

            var category = await _context.Categories
                           .Include(c => c.ComponentTypeCategories)
                           .ThenInclude(c => c.ComponentType)
                           .SingleAsync(c => c.CategoryID == id);

            ViewData["CategoryName"] = category.Name;

            var selectedComponentTypeIds = new List <long>();


            foreach (var ctc in category.ComponentTypeCategories)
            {
                selectedComponentTypeIds.Add(ctc.ComponentType.ComponentTypeID);
            }

            var componentTypes = await _context.ComponentTypes
                                 .Where(ct => selectedComponentTypeIds.Contains(ct.ComponentTypeID))
                                 .Include(ct => ct.ComponentTypeCategories)
                                 .ThenInclude(ct => ct.Category)
                                 .ToListAsync();

            viewModel.ComponentTypes = componentTypes;

            return(View(viewModel));
        }