public async Task InsertGroupSampleData() { const string groupFormat = "Group{0}"; const string descriptionFormat = "Description{0}"; var teachers = await _usersRepository.GetAllByRoleName(RoleConstants.TeacherRoleName); teachers.Sort((x, emp2) => x.FirstName.CompareTo(emp2.FirstName)); var students = await _usersRepository.GetAllByRoleName(RoleConstants.StudentRoleName); students.Sort((x, emp2) => x.FirstName.CompareTo(emp2.FirstName)); for (var i = 0; i < teachers.Count; i++) { for (var j = 0; j < i; j++) { var groupName = string.Format(groupFormat, j); var descriptionName = string.Format(descriptionFormat, j); var group = await _groupsRepository.InsertAsync(Group.Create(groupName, descriptionName, teachers[i].Id)); for (var k = 0; k < i; k++) { await _groupsRepository.InsertStudentAsync(group.Id, students[k].Id); } } } }
public async Task <IActionResult> Create(CreateGroupViewModel createGroupViewModel) { if (!ModelState.IsValid) { return(View(createGroupViewModel)); } var groupToCreate = Group.Create(createGroupViewModel.Name, createGroupViewModel.Description, _userId); await _groupsRepository.InsertAsync(groupToCreate); return(RedirectToAction(nameof(Edit), new{ Id = groupToCreate.Id })); }