public async Task <IActionResult> Detail([FromRoute] int?type)
        {
            // If no id was in the route, return 404
            if (type == null)
            {
                return(NotFound());
            }

            var model = new ProductTypeDetailViewModel();

            var productType = await context.ProductType
                              .Where(t => t.ProductTypeId == type)
                              .SingleOrDefaultAsync();

            // If product not found, return 404
            if (productType == null)
            {
                return(NotFound());
            }

            model.Products = await(from t in context.Product
                                   where t.ProductTypeId == type
                                   select t).ToListAsync();

            model.ProductType = productType;

            return(View(model));
        }
        //Displays all products in a specific category
        // GET: ProductTypes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            //if not found display 404
            if (id == null)
            {
                return(NotFound());
            }

            //creates a new instance of the viewmodel
            var productTypeViewModel = new ProductTypeDetailViewModel();

            //grabs all product type
            var productType = await _context.ProductType
                              .SingleOrDefaultAsync(m => m.ProductTypeID == id);

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


            productTypeViewModel.Products = await _context.Product
                                            .Where(p => p.ProductTypeID == id)
                                            .ToListAsync();

            productTypeViewModel.ProductType = productType;


            return(View(productTypeViewModel));
        }
        // GET: ProductTypes/Details/5
        public async Task <IActionResult> Details([FromRoute] int?id)
        {
            // If no id was in the route, return 404
            if (id == null)
            {
                return(NotFound());
            }

            /*
             *  Create instance of view model
             */
            ProductTypeDetailViewModel model = new ProductTypeDetailViewModel();

            /*
             *  Write LINQ statement to get requested product type
             */

            var productType = _context.ProductType.Single(t => t.ProductTypeId == id);

            // If product not found, return 404
            if (productType == null)
            {
                return(NotFound());
            }

            /*
             *  Add corresponding products to the view model
             */
            model.Products = await _context.Product.Where(p => p.ProductTypeId == id).ToListAsync();

            // Add the product type to the view model
            model.ProductType = productType;

            return(View(model));
        }
Beispiel #4
0
        public async Task <IActionResult> ProductTypes()
        {
            var model = new ProductTypeDetailViewModel(context);

            model.ProductTypes = await context.ProductType.ToListAsync();

            var queried =
                from prst in context.ProductSubType
                join prdt in context.ProductType on prst.ProductSubTypeId equals prdt.ProductTypeId
                where prst.ProductSubTypeId == prdt.ProductTypeId
                select prst;

            model.ProductSubTypes = await queried.ToListAsync();

            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> ProductTypeDetail([FromRoute] int id)
        {
            // If no id was in the route, return 404
            if (id == null)
            {
                return(NotFound());
            }
            var model = new ProductTypeDetailViewModel(context);

            model.ProductSubTypes = await context.ProductSubType.ToListAsync();

            var queriedProds =
                from prd in context.Product
                join prst in context.ProductSubType on prd.ProductId equals prst.ProductSubTypeId
                where prd.ProductSubTypeId == id
                select prd;

            model.Products = await queriedProds.ToListAsync();

            return(View(model));
        }
Beispiel #6
0
        // GET: ProductTypes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductTypeDetailViewModel productTypeDetails = new ProductTypeDetailViewModel();

            var productType = await _context.ProductType
                              .Include(p => p.Products)
                              .FirstOrDefaultAsync(m => m.ProductTypeId == id);

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

            productTypeDetails.ProductType = productType;

            return(View(productTypeDetails));
        }