public IActionResult TimeDetails(TimeDetailsViewModel timeDetailsVM) { BlockedTime blockedTime = new BlockedTime(); blockedTime.StudentId = timeDetailsVM.StudentId; blockedTime.DayId = timeDetailsVM.DayId; blockedTime.StartTime = timeDetailsVM.StartTime; blockedTime.EndTime = timeDetailsVM.EndTime; _context.Add(blockedTime); _context.SaveChanges(); return(RedirectToAction("TimeDetails", "UniversityUsers", new { timeDetailsVM.StudentId })); }
public IActionResult TimeDetails(int studentId) { TimeDetailsViewModel timeDetailsVM = new TimeDetailsViewModel(); timeDetailsVM.StudentId = studentId; timeDetailsVM.BlockedTimes = _context.BlockedTimes.Where(b => b.StudentId == studentId).ToList(); timeDetailsVM.BlockedTimes.OrderBy(b => b.DayId).ThenBy(b => b.StartTime); var registrations = _context.Registrations.Where(r => r.StudentId == studentId).ToList(); foreach (var registration in registrations) { var timetables = _context.Timetables.Where(t => t.UnitId == registration.UnitId).ToList(); foreach (var timetable in timetables) { timeDetailsVM.Timetables.Add(timetable); } timeDetailsVM.Timetables.OrderBy(t => t.DayId).ThenBy(t => t.StartTime); } return(View(timeDetailsVM)); }