public async Task <ActionResult> UserInfo() { VolunteerRepository repo = new VolunteerRepository(configModel.ConnectionString); CalendarRepository calendarRepo = new CalendarRepository(configModel.ConnectionString); ClassRepository classRepo = new ClassRepository(configModel.ConnectionString); BusRepository busRepo = new BusRepository(configModel.ConnectionString); AttendanceModel attendance; VolunteerModel profile; var user = await userManager.GetUserAsync(User); bool checkedIn = false; List <ClassModel> classes = new List <ClassModel>(); List <BusModel> buses = new List <BusModel>(); // Get the current user's profile try { profile = repo.GetVolunteer(user.VolunteerId); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } if (profile == null) { return(Utilities.ErrorJson("Could not find user profile")); } if (configModel.DebugMode || DateTime.Now.DayOfWeek == DayOfWeek.Saturday) { try { attendance = calendarRepo.GetSingleAttendance(profile.Id, DateTime.Now.Date); // determine if the current user has been checked in today if (attendance != null && attendance.Attended == true) { checkedIn = true; } // Get the classes the user teaches and buses the user drives classes = classRepo.GetClasses(true).Where(c => c.TeacherId == profile.Id).ToList(); buses = busRepo.GetBusList(true).Where(b => b.DriverId == profile.Id).ToList(); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } } return(new JsonResult(new { Error = "", Profile = profile, CheckedIn = checkedIn, Classes = classes, Buses = buses })); }
public async Task <IActionResult> BusList() { var user = await userManager.GetUserAsync(User); BusRepository busRepo = new BusRepository(configModel.ConnectionString); List <BusModel> buses; bool staff = await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()); try { buses = busRepo.GetBusList(staff); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "", Buses = buses })); }