public async Task <ActionResult> CreateMakeup(LessonAndStudentsViewModel group) { try { string userId = User.Identity.GetUserId(); Person teacher = context.People.Where(t => t.ApplicationId == userId).FirstOrDefault(); Lesson makeup = group.lesson; makeup.teacherId = teacher.PersonId; makeup.requiresMakeup = true; makeup.start = DateTime.Now; makeup.end = DateTime.Now; // Person student = context.People.Where(p => p.PersonId == makeup.studentId).FirstOrDefault(); // makeup.studentId = student.PersonId; context.Lessons.Add(makeup); await context.SaveChangesAsync(); return(RedirectToAction("TeacherIndex", "Person")); } catch (Exception e) { Console.WriteLine(e); return(View()); } }
public ActionResult CreateMakeup() { string userId = User.Identity.GetUserId(); Person teacher = context.People.Where(t => t.ApplicationId == userId).FirstOrDefault(); List <Person> allStudents = context.People.Where(p => p.PersonId != teacher.PersonId).ToList(); LessonAndStudentsViewModel group = new LessonAndStudentsViewModel(); Lesson makeup = new Lesson(); makeup.requiresMakeup = true; makeup.teacherId = teacher.PersonId; group.lesson = makeup; group.students = allStudents; return(View(group)); }