public async Task <IActionResult> Create(ClasseCourseModel model) { try { var courses = new List <Course>(); var ClassId = model.ClassId; courses = model.Courses; for (int i = 0; i < courses.Count(); i++) { if (courses[i].CheckboxAnswer == true) { var cca = new ClassesCourses(); cca.CourseId = courses[i].Id; cca.ClassId = ClassId; cc.Add(cca); } } await cc.SaveChangesAsync(); return(RedirectToAction("Index", "Classe")); } catch (Exception) { throw; } }
public PartialViewResult Create(int id) { var model = new ClasseCourseModel(); model.Classe = cls.GetById(id); model.ClassId = model.Classe.Id; model.Courses = crs.GetAll(); return(PartialView(model)); }