// 개인회원 스케쥴 조회 public ChangeScheduleViewModel GetOneSchedules(int?studentId) { var query = from schedule in context.Schedules from teacher in context.Teachers join student in context.Students on new { teacher.TeacherId, schedule.StudentId } equals new { student.TeacherId, student.StudentId } where schedule.StudentId == studentId orderby schedule.ScheduleTime descending select new { student, teacher, schedule }; ChangeScheduleViewModel changeScheduleViewModel = null; if (query.Any()) { changeScheduleViewModel = new ChangeScheduleViewModel() { Teacher = query.FirstOrDefault().teacher, Student = query.FirstOrDefault().student, Schedules = new List <Schedule>() }; foreach (var s in query) { changeScheduleViewModel.Schedules.Add(s.schedule); } } else { changeScheduleViewModel = new ChangeScheduleViewModel() { Student = context.Students.Where(s => s.StudentId == studentId).FirstOrDefault() }; } return(changeScheduleViewModel); }
public ChangeScheduleViewModel MySchedule(string email) // User.Identity.Name => Email { var query = from schedule in context.Schedules from teacher in context.Teachers join student in context.Students on new { teacher.TeacherId, schedule.StudentId } equals new { student.TeacherId, student.StudentId } where student.Email == email orderby schedule.ScheduleTime descending select new { student, teacher, schedule }; ChangeScheduleViewModel changeScheduleViewModel = null; if (query.Any()) { changeScheduleViewModel = new ChangeScheduleViewModel() { Teacher = query.FirstOrDefault().teacher, Student = query.FirstOrDefault().student, Schedules = new List <Schedule>() }; foreach (var s in query) { changeScheduleViewModel.Schedules.Add(s.schedule); } } return(changeScheduleViewModel); }
// 스케쥴 추가 public void Add(ChangeScheduleViewModel model) { Schedule schedule = new Schedule { ScheduleTime = new DateTime(model.ScheduleYear, model.ScheduleMonth, model.ScheduleDay, model.ScheduleHour, 0, 0), StudentId = model.StudentId, LessonStatus = Schedule.Status.Waiting }; context.Schedules.Add(schedule); }
// 스케쥴 개인 조회 public IActionResult MySchedule(string id) // User.Identity.Name => Email { ChangeScheduleViewModel viewModel = scheduleRepository.MySchedule(id); if (viewModel == null) { return(RedirectToAction("Index", "Home")); } return(View(viewModel)); }
// 스케쥴 추가 public IActionResult ChangeSchedule(ChangeScheduleViewModel model) { if (model.ScheduleId != 0) // 스케쥴 삭제 { scheduleRepository.Delete(model.ScheduleId); scheduleRepository.Save(); } else // 스케쥴 추가 { scheduleRepository.Add(model); } scheduleRepository.Save(); return(RedirectToAction("ChangeSchedule")); }
public async Task <IActionResult> ChangeSchedule(string id, string returnUrl) { if (string.IsNullOrEmpty(id)) { id = _userManager.GetUserId(User); } var viewModel = new ChangeScheduleViewModel { ReturnUrl = returnUrl, DoctorId = id }; viewModel.Schedules = await _doctorService.GetScheduleByDocId(id).ToArrayAsync(); viewModel.Doctor = await _doctorService.GetDoctorByIdAsync(id); return(View(viewModel)); }
// 스케쥴 변경 페이지 public IActionResult ChangeSchedule(int?id) // Student.StudentId { ChangeScheduleViewModel viewModel = scheduleRepository.GetOneSchedules(id); return(View(viewModel)); }