// GET: Providers public async Task <IActionResult> Index(int?id, int?drinkID) { var viewModel = new ProviderIndexData(); viewModel.Providers = await _context.Providers .Include(i => i.ProvidedDrinks) .ThenInclude(i => i.Drink) .ThenInclude(i => i.Orders) .ThenInclude(i => i.Customer) .AsNoTracking() .OrderBy(i => i.ProviderName) .ToListAsync(); if (id != null) { ViewData["ProviderID"] = id.Value; Provider provider = viewModel.Providers.Where(i => i.ID == id.Value).Single(); viewModel.Drinks = provider.ProvidedDrinks.Select(s => s.Drink); } if (drinkID != null) { ViewData["DrinkID"] = drinkID.Value; viewModel.Orders = viewModel.Drinks.Where(x => x.ID == drinkID).Single().Orders; } return(View(viewModel)); }
// GET: Providers public async Task <IActionResult> Index(int?id, string sortOrder, string searchString) { //var mvcTpvContext = _context.Providers.Include(p => p.Category); var viewModel = new ProviderIndexData(); viewModel.Providers = await _context.Providers .Include(i => i.Inputs) .ThenInclude(i => i.InputDetails) .AsNoTracking() .OrderBy(i => i.ProviderID) .ToListAsync(); //sorting by name and date ViewData["CurrentSort"] = sortOrder; ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date"; switch (sortOrder) { case "name_desc": viewModel.Providers = viewModel.Providers.OrderByDescending(s => s.LastName); break; case "Date": viewModel.Providers = viewModel.Providers.OrderBy(s => s.HighDate); break; case "date_desc": viewModel.Providers = viewModel.Providers.OrderByDescending(s => s.HighDate); break; default: viewModel.Providers = viewModel.Providers.OrderBy(s => s.LastName); break; } ViewData["CurrentFilter"] = searchString; // var provider = from s in _context.Providers // select s; if (id != null) { ViewData["ProviderID"] = id.Value; //viewModel.Providers = await _context.Providers // .Include(i => i.Inputs) // .ThenInclude(i => i.InputDetails) // // .AsNoTracking() // .OrderBy(i => i.ProviderID) // .ToListAsync(); Provider provider = viewModel.Providers .Where(p => p.ProviderID == id.Value) .Single(); viewModel.Inputs = provider.Inputs.ToList(); } if (!String.IsNullOrEmpty(searchString)) { var provider = from p in _context.Providers select p; provider = provider.Where(p => p.FirstMidName.ToUpper().Contains(searchString.ToUpper()) || p.LastName.ToUpper().Contains(searchString.ToUpper()) || p.Direccion.ToUpper().Contains(searchString.ToUpper()) || p.Email.Contains(searchString) || p.TipoDocumento.Contains(searchString) || p.NumDocumento.Contains(searchString) || p.Telefono.Contains(searchString) ); viewModel.Providers = provider.ToList(); } return(View(viewModel)); //return View(await provider.ToListAsync()); //return View(await mvcTpvContext.ToListAsync()); }