Exemple #1
0
        public async Task <ActionResult> MaintenanceFormsCreation(MaintenanceModel maintenance)
        {
            BusModel bus;
            MaintenanceRepository repo          = new MaintenanceRepository(configModel.ConnectionString);
            BusRepository         busRepo       = new BusRepository(configModel.ConnectionString);
            VolunteerRepository   volunteerRepo = new VolunteerRepository(configModel.ConnectionString);
            var user = await userManager.GetUserAsync(User);

            VolunteerModel profile;

            if (user == null || !User.IsInRole(UserHelpers.UserRoles.BusDriver.ToString()))
            {
                return(Utilities.ErrorJson("Not authorized"));
            }

            bus = busRepo.GetBus(maintenance.BusId);

            if (bus == null)
            {
                return(Utilities.ErrorJson("Invalid bus id"));
            }

            if (String.IsNullOrEmpty(maintenance.Text))
            {
                return(Utilities.ErrorJson("Text cannot be empty"));
            }

            profile = volunteerRepo.GetVolunteer(user.VolunteerId);

            repo.CreateMaintenanceForm(maintenance.BusId, maintenance.Text, profile.PreferredName + " " + profile.LastName);

            return(Utilities.NoErrorJson());
        }
Exemple #2
0
        public async Task <IActionResult> BusEdit(BusModel model)
        {
            BusRepository repo = new BusRepository(configModel.ConnectionString);
            BusModel      bus;
            var           user = await userManager.GetUserAsync(User);

            // Make sure the user is a maintenance worker
            if (!await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusMaintenance.ToString()))
            {
                return(Utilities.ErrorJson("Unauthorized"));
            }

            // Validate the input
            bus = repo.GetBus(model.Id);

            if (bus == null)
            {
                return(Utilities.ErrorJson("Invalid bus id"));
            }

            try
            {
                repo.UpdateBus(model.Id, model.LastMaintenance, model.LastOilChange, model.LastTireChange);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(Utilities.NoErrorJson());
        }
        public IEnumerable <AllBusModel> Get()
        {
            BusRepository busRepository = new BusRepository();

            return(busRepository.GetBus().ToList()
                   .Select(x => new AllBusModel
            {
                Bus = x.buszId
            }));
        }
Exemple #4
0
        public async Task <IActionResult> AssignBusDriver(BusModel model)
        {
            VolunteerRepository repo    = new VolunteerRepository(configModel.ConnectionString);
            BusRepository       busRepo = new BusRepository(configModel.ConnectionString);
            BusModel            bus;
            VolunteerModel      profile;
            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"));
            }

            // Validate the inputs
            bus = busRepo.GetBus(model.Id);

            if (bus == null)
            {
                return(Utilities.ErrorJson("Invalid bus id"));
            }

            profile = repo.GetVolunteer(model.DriverId);

            if (profile == null)
            {
                return(Utilities.ErrorJson("Invalid driver id"));
            }

            if (profile.Role != UserHelpers.UserRoles.BusDriver.ToString())
            {
                return(Utilities.ErrorJson("That user is not a bus driver"));
            }

            // Update in the database
            try
            {
                busRepo.AssignDriver(model.Id, model.DriverId);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(Utilities.NoErrorJson());
        }
Exemple #5
0
        public async Task <IActionResult> BusInfo(int id)
        {
            var user = await userManager.GetUserAsync(User);

            BusRepository busRepo = new BusRepository(configModel.ConnectionString);
            BusModel      bus;

            // 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"));
            }

            if (id == 0)
            {
                return(Utilities.ErrorJson("Must include a bus id"));
            }

            try
            {
                bus = busRepo.GetBus(id);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            if (bus == null)
            {
                return(Utilities.ErrorJson("That bus does not exist"));
            }

            return(new JsonResult(new
            {
                Error = "",
                Bus = bus
            }));
        }
Exemple #6
0
        public async Task <IActionResult> RouteEdit(BusModel bus)
        {
            var user = await userManager.GetUserAsync(User);

            BusRepository busRepo = new BusRepository(configModel.ConnectionString);
            BusModel      dbBus;

            // 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"));
            }

            if (string.IsNullOrEmpty(bus.Name))
            {
                return(Utilities.ErrorJson("Bus name cannot be empty"));
            }
            if (bus.Name.Length > 300)
            {
                return(Utilities.ErrorJson("Bus name is too long (limit 300 characters)"));
            }

            // Get the bus to ensure that it is valid
            dbBus = busRepo.GetBus(bus.Id);
            if (bus.Id == 0 || bus == null)
            {
                return(Utilities.ErrorJson("Invalid id"));
            }

            busRepo.UpdateBusRoute(bus.Id, bus.Name, bus.Route);

            return(new JsonResult(new
            {
                Error = ""
            }));
        }
Exemple #7
0
 public ActionResult Manage_Bus()
 {
     busList = busRepository.GetBus();
     return(View(busList));
 }
Exemple #8
0
        public ActionResult Edit(string type)
        {
            BusEntity bus = busRepository.GetBus(type);

            return(View(bus));
        }