예제 #1
0
 public async Task OnGetAsync()
 {
     //Customer = await _context.Customers.ToListAsync();
     CustomerData           = new CustomerIndexData();
     CustomerData.Customers = await _context.Customers
                              .Include(customer => customer.Orders)
                              .AsNoTracking()
                              .ToListAsync();
 }
예제 #2
0
        // GET: Customers
        public async Task <IActionResult> Index(int?id, int?addressID)
        {
            var viewModel = new CustomerIndexData();

            viewModel.Customers = await _context.Customers

                                  .Include(i => i.Addresses)
                                  .AsNoTracking()
                                  .OrderBy(i => i.FirstName)
                                  .ToListAsync();

            //if(id != null)
            //{
            //    ViewData["CustomerID"] = id.Value;
            //    Customer customer = viewModel.Customers.Where(
            //        i => i.CustomerID == id.Value).Single();
            //    viewModel.Addresses = (IEnumerable<Address>)customer.Addresses.Select(s => s.StreetAddress);

            //}
            return(View(viewModel));
        }
        public async Task <IActionResult> CustomerIndexDetail(int?id, int?projectID, string sortOrder, string currentFillter, string searchString)
        {
            ViewData["CurrentPage"] = "CustomerIndexDetail";
            var viewModel = new CustomerIndexData();

            viewModel.Customers = await _context.Customers
                                  .Include(c => c.Projects)
                                  .ThenInclude(c => c.Tasks)
                                  .AsNoTracking()
                                  .ToListAsync();

            ViewData["CurrentSort"]     = sortOrder;
            ViewData["IDSortParm"]      = string.IsNullOrEmpty(sortOrder) ? "id_desc" : "";
            ViewData["NameSortParm"]    = sortOrder == "Name" ? "name_desc" : "Name";
            ViewData["AddressSortParm"] = sortOrder == "Address" ? "address_desc" : "Address";
            ViewData["TMSortParm"]      = sortOrder == "TM" ? "tm_desc" : "TM";
            ViewData["StatusSortParm"]  = sortOrder == "Status" ? "status_desc" : "Status";

            if (searchString == null)
            {
                searchString = currentFillter;
            }
            ViewData["CurrentFilter"] = searchString;

            if (!string.IsNullOrEmpty(searchString))
            {
                viewModel.Projects = viewModel.Projects.Where(p => p.Site.Contains(searchString) || p.SiteManager.Contains(searchString) ||
                                                              p.TowerManager.Contains(searchString) || p.Status.ToString().Contains(searchString));
            }

            if (id != null)
            {
                ViewData["ID"] = id.Value;
                Customer customer = viewModel.Customers.Where(c => c.ID == id.Value).Single();
                viewModel.Projects = customer.Projects;
            }
            if (projectID != null)
            {
                ViewData["projectId"] = projectID.Value;
                viewModel.Tasks       = viewModel.Projects.Where(p => p.SiteID == projectID).Single().Tasks;
            }

            switch (sortOrder)
            {
            case "id_desc":
                viewModel.Projects = viewModel.Projects.OrderByDescending(p => p.SiteID); break;

            case "Name":
                viewModel.Projects = viewModel.Projects.OrderBy(p => p.Site); break;

            case "name_desc":
                viewModel.Projects = viewModel.Projects.OrderByDescending(p => p.Site); break;

            case "Address":
                viewModel.Projects = viewModel.Projects.OrderBy(p => p.Address); break;

            case "address_desc":
                viewModel.Projects = viewModel.Projects.OrderByDescending(p => p.Address); break;

            case "TM":
                viewModel.Projects = viewModel.Projects.OrderBy(p => p.TowerManager); break;

            case "tm_desc":
                viewModel.Projects = viewModel.Projects.OrderByDescending(p => p.TowerManager); break;

            case "Status":
                viewModel.Projects = viewModel.Projects.OrderBy(p => p.Status); break;

            case "status_desc":
                viewModel.Projects = viewModel.Projects.OrderByDescending(p => p.Status); break;

            default:
                viewModel.Projects = viewModel.Projects.OrderBy(p => p.SiteID); break;
            }
            return(View(viewModel));
        }
예제 #4
0
        // GET: Customers
        public async Task <IActionResult> Index(int?id, int?saleID, string sortOrder, string searchString)
        {
            var viewModel = new CustomerIndexData();

            viewModel.Customers = await _context.Customers
                                  .Include(c => c.Sales)
                                  .ThenInclude(i => i.SaleDetails)
                                  .AsNoTracking()
                                  .OrderBy(i => i.CustomerID)
                                  .ToListAsync();

            ViewData["CurrentSort"]  = sortOrder;
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";

            switch (sortOrder)
            {
            case "name_desc":
                viewModel.Customers = viewModel.Customers.OrderByDescending(c => c.LastName);
                break;

            case "Date":
                viewModel.Customers = viewModel.Customers.OrderBy(c => c.HighDate);
                break;

            case "date_desc":
                viewModel.Customers = viewModel.Customers.OrderByDescending(c => c.HighDate);
                break;

            default:
                viewModel.Customers = viewModel.Customers.OrderBy(c => c.LastName);
                break;
            }
            ViewData["CurrentFilter"] = searchString;


            if (id != null)
            {
                ViewData["CustomerID"] = id.Value;

                //viewModel.Customers = await _context.Customers
                //           .Include(c => c.Sales)
                //               .ThenInclude(i => i.SaleDetails)
                //           //.AsNoTracking()
                //           .OrderBy(i => i.CustomerID)
                //           .ToListAsync();

                Customer customer = viewModel.Customers
                                    .Where(p => p.CustomerID == id.Value)
                                    .Single();

                viewModel.Sales = customer.Sales.ToList();
            }
            if (!String.IsNullOrEmpty(searchString))
            {
                var customer = from c in _context.Customers
                               select c;
                customer = customer.Where(c => c.FirstMidName.ToUpper().Contains(searchString.ToUpper()) ||
                                          c.LastName.ToUpper().Contains(searchString.ToUpper()) ||
                                          c.Direccion.ToUpper().Contains(searchString.ToUpper()) ||
                                          c.Email.Contains(searchString) ||
                                          c.TipoDocumento.Contains(searchString) ||
                                          c.NumDocumento.Contains(searchString) ||
                                          c.Telefono.Contains(searchString)

                                          );

                viewModel.Customers = customer.ToList();
            }

            return(View(viewModel));
            //return View(await customer.ToListAsync());
            //return View(await _context.Customers.ToListAsync());
        }