Beispiel #1
0
        // GET: ProductGuides
        public async Task <IActionResult> Index(int?id, int?productID)
        {
            var viewModel = new ProductGuideIndexData();

            viewModel.ProductGuides = await _context.ProductGuides
                                      .Include(i => i.CountryAssignment)
                                      .Include(i => i.ProductAssignments)
                                      .ThenInclude(i => i.Product)
                                      .ThenInclude(i => i.Subscriptions)
                                      .ThenInclude(i => i.Customer)
                                      .Include(i => i.ProductAssignments)
                                      .ThenInclude(i => i.Product)
                                      .ThenInclude(i => i.Market)
                                      .AsNoTracking()
                                      .OrderBy(i => i.LastName)
                                      .ToListAsync();

            if (id != null)
            {
                ViewData["ProductGuideID"] = id.Value;
                ProductGuide productGuide = viewModel.ProductGuides.Where(
                    i => i.ID == id.Value).Single();
                viewModel.Products = productGuide.ProductAssignments.Select(s => s.Product);
            }

            if (productID != null)
            {
                ViewData["ProductID"] = productID.Value;
                var selectedProduct = viewModel.Products.Where(x => x.ProductID == productID).Single();
                await _context.Entry(selectedProduct).Collection(x => x.Subscriptions).LoadAsync();

                foreach (Subscription subscription in selectedProduct.Subscriptions)
                {
                    await _context.Entry(subscription).Reference(x => x.Customer).LoadAsync();
                }
                viewModel.Subscriptions = selectedProduct.Subscriptions;
            }

            return(View(viewModel));
        }
Beispiel #2
0
        public async Task OnGetAsync(int?id, int?productID)
        {
            ProductGuideData = new ProductGuideIndexData();
            ProductGuideData.ProductGuides = await _context.ProductGuides
                                             .Include(pg => pg.CountryAssignment)
                                             .Include(pg => pg.ProductAssignments)
                                             .ThenInclude(pg => pg.Product)
                                             .ThenInclude(pg => pg.Market)
                                             // .Include(pg => pg.ProductAssignments)
                                             //   .ThenInclude(pg => pg.Product)
                                             //     .ThenInclude(pg => pg.Subscriptions)
                                             //       .ThenInclude(pg => pg.Customer)
                                             // .AsNoTracking()
                                             .OrderBy(pg => pg.LastName)
                                             .ToListAsync();

            if (id != null)
            {
                ProductGuideID = id.Value;
                ProductGuide productGuide = ProductGuideData.ProductGuides
                                            .Where(pg => pg.ID == id.Value).Single();
                ProductGuideData.Products = productGuide.ProductAssignments.Select(pa => pa.Product);
            }

            if (productID != null)
            {
                ProductID = productID.Value;
                var selectedProduct = ProductGuideData.Products
                                      .Where(pg => pg.ProductID == productID).Single();
                await _context.Entry(selectedProduct).Collection(x => x.Subscriptions).LoadAsync();

                foreach (Subscription subscription in selectedProduct.Subscriptions)
                {
                    await _context.Entry(subscription).Reference(x => x.Customer).LoadAsync();
                }
                ProductGuideData.Subscriptions = selectedProduct.Subscriptions;
            }
        }