public void OnSubmit() { if (ClassName == null) { DisplayInvalidClass(); } else if (StreamName == null) { DisplayInvalidStream(); } else if (SectionName == null) { DisplayInvalidSection(); } else { try { MasterChooseDetails.ClassMaster_Code = ClassName.Id; MasterChooseDetails.SectionMaster_Code = SectionName.Id; MasterChooseDetails.StreamMaster_Code = StreamName.Id; GeneralMethod glMethod = new GeneralMethod(); if (UserType.currentAttendanceType != UserType.attendanceType.TimeTable) { TakeAttendanceViewModel.bindAttendanceData(); } else { TimeTableGroup.LoadTimeTable(); } UserDialogs.Instance.HideLoading(); CommendClose(); } catch (Exception ex) { } } }
public async Task <IActionResult> Create(TimeTableViewModel model) { if (ModelState.IsValid) { TimeTable timeTable = new TimeTable { DateTime = model.DateTime, DayNumber = model.DateTime.Day, PatternType = "Рабочий", SemesterId = null, //TODO: Нужен ли семестр? || НЕ НУЖЕН) }; await _context.TimeTables.AddAsync(timeTable); await _context.SaveChangesAsync(); //model.TimeTableGroup.GroupId = model.GroupId; //model.TimeTableGroup.TimeTableId = timeTable.TimeTableId; TimeTableGroup timeTableGroup = new TimeTableGroup { GroupId = model.GroupId, TimeTableId = timeTable.TimeTableId }; await _context.TimeTableGroups.AddAsync(timeTableGroup); await _context.SaveChangesAsync(); for (int i = 0; i < model.Lessons.Count() / 2; i++) { Couple couple = new Couple() { TimeTableGroupId = timeTableGroup.TimeTableGroupId }; await _context.Couples.AddAsync(couple); await _context.SaveChangesAsync(); List <Lesson> lessons = model.Lessons.GetRange(i * 2, 2).Select(i => new Lesson { CoupleId = couple.CoupleId, AudienceId = i.AudienceId, DisciplineId = i.DisciplineId, UserId = i.TeacherId }).ToList(); await _context.Lessons.AddRangeAsync(lessons); await _context.SaveChangesAsync(); } //List<Couple> Couples = model.Couples.Select(i => new Couple //{ // IsSubgroups = false, // Subgroups = 0, // DisciplineId = i.DisciplineId, // AudienceId = i.AudienceId, // UserId = i.TeacherId, // TimeTableGroupId = timeTableGroup.TimeTableGroupId //}).ToList(); return(RedirectToAction("Index")); } else { model.Audiences = await _context.Audiences.ToListAsync(); model.Disciplines = await _context.Disciplines.ToListAsync(); model.Groups = await _context.Groups.ToListAsync(); model.Teachers = await _userManager.GetUsersInRoleAsync("преподаватель"); return(View(model)); } }