public ActionResult AddRehearsalPart(AdminHomeVM vm) { PeriodBuilder builder = new PeriodBuilder(); builder.Minutes = vm.NewRehearsalPart.IntLengthMinutes; vm.NewRehearsalPart.DurLength = builder.Build(); GetDAL get = new GetDAL(); get.OpenConnection(); foreach (var id in vm.NewRehearsalPart.ArrMemberNeededIDs) { Users tmpUser = get.GetUserByID(id); vm.NewRehearsalPart.LstMembers.Add(tmpUser); } get.CloseConnection(); InsertDAL insert = new InsertDAL(); insert.OpenConnection(); int newRehearsalPartID = insert.InsertRehearsalPart(vm.NewRehearsalPart); vm.NewRehearsalPart.IntRehearsalPartID = newRehearsalPartID; foreach (var m in vm.NewRehearsalPart.LstMembers) { AttendancePlanned ap = new AttendancePlanned(vm.NewRehearsalPart, m); insert.InsertAttendancePlanned(ap); } insert.CloseConnection(); return(RedirectToAction("Index")); }