示例#1
0
        public async Task <IActionResult> GetBusDrivers(DateTime date)
        {
            VolunteerRepository    repo = new VolunteerRepository(configModel.ConnectionString);
            List <DriverListModel> drivers;
            var user = await userManager.GetUserAsync(User);

            /// Ensure that ONLY staff accounts have access to this API endpoint
            if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()))
            {
                return(Utilities.ErrorJson("Not authorized"));
            }

            try
            {
                if (date != DateTime.MinValue)
                {
                    drivers = repo.GetBusDrivers(date);
                }
                else
                {
                    drivers = repo.GetBusDrivers();
                }
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(new JsonResult(new {
                Error = "",
                Drivers = drivers
            }));
        }