Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,StudentID,TripID,StatusOfPickUp,LoggedPickupTime")] TripAssignment tripAssignment)
        {
            if (id != tripAssignment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tripAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TripAssignmentExists(tripAssignment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "FirstMidName", tripAssignment.StudentID);
            ViewData["TripID"]    = new SelectList(_context.Trips, "ID", "WeekdayDay", tripAssignment.TripID);
            return(View(tripAssignment));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,PickupTime,Complete,BusID,DriverID")] Trip trip, string[] selectedStudents, DateTime PickupTime)
        {
            string day = PickupTime.DayOfWeek == DayOfWeek.Monday ? "Monday" :
                         PickupTime.DayOfWeek == DayOfWeek.Tuesday ? "Tuesday" :
                         PickupTime.DayOfWeek == DayOfWeek.Wednesday ? "Wednesday" :
                         PickupTime.DayOfWeek == DayOfWeek.Thursday ? "Thursday" :
                         PickupTime.DayOfWeek == DayOfWeek.Friday ? "Friday" : "Index";

            if (selectedStudents != null)
            {
                trip.TripAssignments = new List <TripAssignment>();
                foreach (var students in selectedStudents)
                {
                    var studentToAdd = new TripAssignment {
                        TripID = trip.ID, StudentID = int.Parse(students), StatusOfPickUp = StatusOfPickUp.Scheduled
                    };
                    trip.TripAssignments.Add(studentToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(trip);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(day));
                return(RedirectToAction(day));
            }
            ViewBag.BusID        = new SelectList(_context.Buses, "ID", "IDwithCapacity", trip.BusID, "Capacity");
            ViewData["DriverID"] = _context.Drivers.Include(d => d.User).ToList();
            ViewData["Schools"]  = _context.School.OrderBy(z => z.Name).ToList();
            //ViewData["DriverID"] = new SelectList(_context.Drivers, "UserID", "UserID", trip.DriverID);
            PopulateAssignedStudentData(trip, PickupTime);
            return(View(trip));
        }
Exemplo n.º 3
0
        //
        // UpdateInstructorCourses Microsoft tutorial
        //
        private void UpdateTripStudents(string[] selectedStudents, Trip tripToUpdate)
        {
            if (selectedStudents == null)
            {
                tripToUpdate.TripAssignments = new List <TripAssignment>();
                return;
            }

            var selectedStudentsHS = new HashSet <string>(selectedStudents);
            var tripStudents       = new HashSet <int>
                                         (tripToUpdate.TripAssignments.Select(s => s.Student.ID));

            foreach (var student in _context.Students)
            {
                if (selectedStudentsHS.Contains(student.ID.ToString()))
                {
                    if (!tripStudents.Contains(student.ID))
                    {
                        tripToUpdate.TripAssignments.Add(new TripAssignment {
                            TripID = tripToUpdate.ID, StudentID = student.ID, StatusOfPickUp = StatusOfPickUp.Scheduled
                        });
                    }
                }
                else
                {
                    if (tripStudents.Contains(student.ID))
                    {
                        TripAssignment studentToRemove = tripToUpdate.TripAssignments.SingleOrDefault(t => t.StudentID == student.ID);
                        _context.Remove(studentToRemove);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RollCallEdit(int id, [Bind("ID,StudentID,TripID,StatusOfPickUp,LoggedPickupTime")] TripAssignment tripAssignment, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            //Below var is just for the redirect ID
            var tripID = tripAssignment.TripID;

            if (id != tripAssignment.ID)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tripAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TripAssignmentExists(tripAssignment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
                return(Redirect("RoleCall/" + tripID + "?returnurl=" + returnUrl));
            }
            return(View());
        }