Exemple #1
0
        // GET: ProductTypes​

        public async Task <IActionResult> Index()
        {
            var model = new ProductTypesViewModel();

            model.GroupedProducts = await _context.ProductType.Select
                                        (pt => new GroupedProducts
            {
                TypeId       = pt.ProductTypeId,
                TypeName     = pt.Label,
                ProductCount = pt.Products.Count(),
                Products     = pt.Products.OrderByDescending(p => p.DateCreated).Take(3)
            }).ToListAsync();

            return(View(model));
        }
        private ProductTypesViewModel Types()
        {
            var model = new ProductTypesViewModel();

            model.Types = _context
                          .ProductType
                          .Select(pt => new TypeWithProducts()
            {
                TypeId       = pt.ProductTypeId,
                TypeName     = pt.Label,
                ProductCount = pt.Products.Count(),
                Products     = pt.Products.OrderByDescending(p => p.DateCreated).Take(3).ToList()
            }).ToList();

            return(model);
        }
        // GET: ProductType
        public async Task <ActionResult> Index()
        {
            var viewModel = new ProductTypesViewModel();

            viewModel.Categories = await _context
                                   .ProductType
                                   .Select(pt => new ProductCategories()
            {
                CategoryId   = pt.ProductTypeId,
                CategoryName = pt.Label,
                ProductCount = pt.Products.Count(),
                Products     = pt.Products.OrderByDescending(p => p.DateCreated).Take(3)
            }).ToListAsync();

            return(View(viewModel));
        }
        //Method: Purpose is to render the ProductTypes view, which displays all product categories
        public async Task <IActionResult> Types()
        {
            //This creates a new instance of the ProductTypesViewModel and passes in the current session with the database (context) as an argument

            ProductTypesViewModel model = new ProductTypesViewModel(context);

            model.ProductTypes = await context.ProductType.OrderBy(s => s.Label).ToListAsync();

            model.ProductTypeSubCategories = await context.ProductTypeSubCategory.OrderBy(s => s.Name).ToListAsync();

            //list of subcategories
            var subCats = context.ProductTypeSubCategory.ToList();

            //cycle through each subcategory and define its Quantity as
            subCats.ForEach(sc => sc.Quantity = context.Product.Count(p => p.ProductTypeSubCategoryId == sc.ProductTypeSubCategoryId));
            // model.ProductTypes = productTypes;
            return(View(model));
        }
Exemple #5
0
        public async Task <IActionResult> Types()
        {
            var model = new ProductTypesViewModel();

            var GroupedProducts = await(
                from t in _context.ProductType
                join p in _context.Product
                on t.ProductTypeId equals p.ProductTypeId
                group new { t, p } by new { t.ProductTypeId, t.Label } into grouped
                select new GroupedProducts {
                TypeId       = grouped.Key.ProductTypeId,
                TypeName     = grouped.Key.Label,
                ProductCount = grouped.Select(x => x.p.ProductId).Count(),
                Products     = grouped.Select(x => x.p).Take(3).ToList()
            }).ToListAsync();

            model.GroupedProducts = GroupedProducts;
            return(View(model));
        }
Exemple #6
0
        public async Task <IActionResult> Types()
        {
            var model = new ProductTypesViewModel();

            // Get line items grouped by product id, including count
            var counter = from product in context.Product
                          group product by product.ProductTypeId into grouped
                          select new { grouped.Key, myCount = grouped.Count() };

            // Build list of Product instances for display in view
            model.ProductTypes = await(from type in context.ProductType
                                       join a in counter on type.ProductTypeId equals a.Key
                                       select new ProductType {
                ProductTypeId = type.ProductTypeId,
                Label         = type.Label,
                Quantity      = a.myCount
            }).ToListAsync();

            return(View(model));
        }
Exemple #7
0
        public async Task <IActionResult> Types()
        {
            var model = new ProductTypesViewModel();

            // Build list of Product instances for display in view
            // LINQ is awesome
            model.GroupedProducts = await(
                from t in _context.ProductType
                join p in _context.Product
                on t.ProductTypeId equals p.ProductTypeId
                group new { t, p } by new { t.ProductTypeId, t.Label } into grouped
                select new GroupedProducts
            {
                TypeId       = grouped.Key.ProductTypeId,
                TypeName     = grouped.Key.Label,
                ProductCount = grouped.Select(x => x.p.ProductId).Count(),
                Products     = grouped.Select(x => x.p).Take(3)
            }).ToListAsync();

            return(View(model));
        }
Exemple #8
0
        public async Task <IActionResult> Types()
        {
            var model = new ProductTypesViewModel();

            // Build list of Product instances for display in view
            // The LINQ statement groups the student entities by enrollment date, calculates the number of entities in each group, and stores the results in a collection of EnrollmentDateGroup view model objects.
            // LINQ is awesome
            model.GroupedProducts = await(
                from t in _context.ProductType
                join p in _context.Product
                on t.ProductTypeId equals p.ProductTypeId
                group new { t, p } by new { t.ProductTypeId, t.Label } into grouped
                select new GroupedProducts
            {
                TypeId       = grouped.Key.ProductTypeId,
                TypeName     = grouped.Key.Label,
                ProductCount = grouped.Select(x => x.p.ProductId).Count(),
                Products     = grouped.Select(x => x.p).Take(3)
            }).ToListAsync();

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

            var model = new ProductTypesViewModel();

            model.GroupedProducts = await _context.ProductType.Select
                                        (pt => new GroupedProducts
            {
                TypeId       = pt.ProductTypeId,
                TypeName     = pt.Label,
                ProductCount = pt.Products.Count(),
                Products     = pt.Products.Where(pt => pt.ProductTypeId == id)
            }).ToListAsync();

            if (model == null)
            {
                return(NotFound());
            }
            return(View(model));
        }