Esempio n. 1
0
        public IActionResult PickupsForToday(CustomerDayViewModel customerDayViewModel)
        {
            var      userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            Employee employee = _context.Employees.Where(c => c.IdentityUserId == userId).SingleOrDefault();
            bool     oneTimePickupIsInView;

            foreach (var customer in _context.Customers)
            {
                oneTimePickupIsInView = false;
                if (customer.OneTimePickup.DayOfWeek == customerDayViewModel.DayOfWeek)
                {
                    oneTimePickupIsInView = true;
                }

                if (_context.Customers.Where(c => (c.ZipCode == employee.ZipCode && oneTimePickupIsInView && c.CustomerId == customer.CustomerId) ||
                                             (c.ZipCode == employee.ZipCode && c.PickupDay == customerDayViewModel.DayOfWeek && c.CustomerId == customer.CustomerId)).SingleOrDefault() != null)
                {
                    customerDayViewModel.Customers.Add(_context.Customers
                                                       .Where(c => (c.ZipCode == employee.ZipCode && oneTimePickupIsInView && c.CustomerId == customer.CustomerId) ||
                                                              (c.ZipCode == employee.ZipCode && c.PickupDay == customerDayViewModel.DayOfWeek && c.CustomerId == customer.CustomerId)).SingleOrDefault());
                }
            }
            //customerDayViewModel.Customers = _context.Customers
            //    .Where(c => (c.ZipCode == employee.ZipCode && c.OneTimePickup.Date == customerDayViewModel) ||
            //    (c.ZipCode == employee.ZipCode && c.PickupDay == customerDayViewModel.DayOfWeek)).ToList();
            return(View(customerDayViewModel));
        }
Esempio n. 2
0
        public IActionResult PickupsForToday(int?id)
        {
            CustomerDayViewModel customerDayViewModel = new CustomerDayViewModel();

            customerDayViewModel.DayOfWeek = DateTime.Today.DayOfWeek;
            Employee employee = _context.Employees
                                .Include(c => c.IdentityUser)
                                .FirstOrDefault(e => e.EmployeeId == id);
            bool oneTimePickupIsInView;

            foreach (var customer in _context.Customers)
            {
                oneTimePickupIsInView = false;
                if (customer.OneTimePickup.DayOfWeek == customerDayViewModel.DayOfWeek)
                {
                    oneTimePickupIsInView = true;
                }

                if (_context.Customers.Where(c => (c.ZipCode == employee.ZipCode && oneTimePickupIsInView && c.CustomerId == customer.CustomerId) ||
                                             (c.ZipCode == employee.ZipCode && c.PickupDay == customerDayViewModel.DayOfWeek && c.CustomerId == customer.CustomerId)).SingleOrDefault() != null)
                {
                    customerDayViewModel.Customers.Add(_context.Customers
                                                       .Where(c => (c.ZipCode == employee.ZipCode && oneTimePickupIsInView && c.CustomerId == customer.CustomerId) ||
                                                              (c.ZipCode == employee.ZipCode && c.PickupDay == customerDayViewModel.DayOfWeek && c.CustomerId == customer.CustomerId)).SingleOrDefault());
                }
            }


            // ||
            //(c.OneTimePickup.DayOfWeek == customerDayViewModel.DayOfWeek)).ToList();
            return(View(customerDayViewModel));
        }