// GET: Employee public IActionResult Index() { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); try { var employee = _context.Employees.Where(e => e.IdentityUserId == userId).SingleOrDefault(); DateTime dt = DateTime.Now; var customerList = _context.Customers.Where(c => c.WeeklyPickupDay == dt.DayOfWeek.ToString() && c.ZipCode == employee.ZipCode).ToList(); foreach (var item in _context.Customers.Where(c => c.OneTimePickup == dt.Date)) { customerList.Add(item); } foreach (var item in _context.Customers.Where(c => c.StartServiceHold <dt.Date && c.EndServiceHold> dt.Date)) { customerList.Remove(item); } var employeeCustomerViewModel = new EmployeeCustomerViewModel(employee, customerList); return(View(employeeCustomerViewModel)); } catch { return(RedirectToAction("Create")); } }
//[HttpPost] //public IActionResult Index(Employee employee) //{ // DateTime dt = DateTime.Now; // var customerList = _context.Customers.Where(c => c.WeeklyPickupDay == (dt.DayOfWeek).ToString() && c.ZipCode == employee.ZipCode); // return View(customerList); //} // Get: Day of Week details public IActionResult DailyDetails(string dayOfWeek) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); try { var employee = _context.Employees.Where(e => e.IdentityUserId == userId).SingleOrDefault(); var customerList = _context.Customers.Where(c => c.WeeklyPickupDay == dayOfWeek && c.ZipCode == employee.ZipCode).ToList(); var employeeCustomerViewModel = new EmployeeCustomerViewModel(employee, customerList); return(View(employeeCustomerViewModel)); } catch { return(RedirectToAction("Index")); } }
// 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)); }
// GET: Customers/SearchPickupsByDay/5 public async Task <IActionResult> SearchPickupsByDay(int WeeklyPickupDayId) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); List <Employee> currentEmployees = _context.Employees.Where(e => e.IdentityUserId == userId).ToList(); List <Customer> todaysCustomers = _context.Customers.Include(c => c.WeeklyPickUpDay) .Where(c => c.ZipCode.Equals(currentEmployees[0].ZipCode) && c.WeeklyPickUpDay.Id.Equals(WeeklyPickupDayId)).ToList(); EmployeeCustomerViewModel ecViewModel = new EmployeeCustomerViewModel { Employees = currentEmployees, Customers = todaysCustomers }; var applicationDbContext = _context.Employees.Include(e => e.IdentityUser); await applicationDbContext.ToListAsync(); return(View(ecViewModel)); }