Exemplo n.º 1
0
        // GET: Employees
        public async Task <IActionResult> Index()
        {
            var    userId             = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            string todaysDayOfTheWeek = DateTime.Today.ToString("dddd");

            List <TemporaryPickupSuspension> temporaryPickupSuspensions;
            List <Customer>      todaysCustomers;
            List <OneTimePickup> oneTimePickups;

            List <Employee> currentEmployees = _context.Employees.Where(e => e.IdentityUserId == userId).ToList();

            if (currentEmployees.Count.Equals(0))
            {
                temporaryPickupSuspensions = null;
                todaysCustomers            = null;
                oneTimePickups             = null;
            }
            else
            {
                temporaryPickupSuspensions = _context.TemporaryPickupSuspensions.Where(t => t.ZipCode.Equals(currentEmployees[0].ZipCode)).ToList();
                todaysCustomers            = _context.Customers.Include(c => c.WeeklyPickUpDay).Include(i => i.IdentityUser)
                                             .Where(c => c.ZipCode.Equals(currentEmployees[0].ZipCode) && c.WeeklyPickUpDay.Day.Equals(todaysDayOfTheWeek) && c.LastPickup.Value.Date != DateTime.Today).ToList();
                oneTimePickups = _context.OneTimePickups.Include(c => c.Customer)
                                 .Where(o => o.ZipCode.Equals(currentEmployees[0].ZipCode) && o.DateForPickup.Date.Equals(DateTime.Today) && o.Customer.LastPickup.Value.Date != DateTime.Today).ToList();
            }


            CustomerPickupInformationViewModel cpInfoViewModel = new CustomerPickupInformationViewModel
            {
                Customers                  = todaysCustomers,
                OneTimePickups             = oneTimePickups,
                TemporaryPickupSuspensions = temporaryPickupSuspensions
            };

            EmployeeCustomerViewModel ecViewModel = new EmployeeCustomerViewModel
            {
                Employees         = currentEmployees,
                WeeklyPickupDayId = 1,
                CustomerPickupInformationViewModel = cpInfoViewModel,
            };

            var applicationDbContext = _context.Employees.Include(e => e.IdentityUser);
            await applicationDbContext.ToListAsync();

            ViewData["WeeklyPickUpDayId"] = new SelectList(_context.WeeklyPickupDays, "Id", "Day");
            return(View(ecViewModel));
        }
Exemplo n.º 2
0
        // GET: Customers
        public async Task <IActionResult> Index()
        {
            var                              userId                     = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            List <Customer>                  currentCustomers           = _context.Customers.Where(c => c.IdentityUserId == userId).Include(i => i.IdentityUser).Include(w => w.WeeklyPickUpDay).ToList();
            List <OneTimePickup>             oneTimePickups             = _context.OneTimePickups.Where(o => o.IdentityUserId == userId).ToList();
            List <TemporaryPickupSuspension> temporaryPickupSuspensions = _context.TemporaryPickupSuspensions.Where(t => t.IdentityUserId == userId).ToList();

            CustomerPickupInformationViewModel cpInfoViewModel = new CustomerPickupInformationViewModel
            {
                Customers                  = currentCustomers,
                OneTimePickups             = oneTimePickups,
                TemporaryPickupSuspensions = temporaryPickupSuspensions
            };

            var applicationDbContext = _context.Customers.Include(e => e.IdentityUser);
            await applicationDbContext.ToListAsync();

            return(View(cpInfoViewModel));
        }