public async Task <IActionResult> Create([Bind("Id,Name,Group")] Student student) { if (ModelState.IsValid) { // register new user var user = new ApplicationUser { UserName = student.Name, Email = $"{student.Name}@gmail.com", EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, "123456"); if (result.Succeeded) { // add new student _context.Add(student); await _context.SaveChangesAsync(); await _userManager.AddClaimAsync(user, new Claim("studentId", student.Id.ToString())); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("Name", result.Errors.First().Description); } } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,Name,Group")] Teacher teacher) { if (ModelState.IsValid) { // register new user var user = new ApplicationUser { UserName = teacher.Name, Email = $"{teacher.Name}@gmail.com", EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, "123456"); if (result.Succeeded) { // add new student _context.Add(teacher); await _context.SaveChangesAsync(); await _userManager.AddClaimAsync(user, new Claim("teacherId", teacher.Id.ToString())); return(RedirectToAction(nameof(Index))); } else { } } return(View(teacher)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Teacher teacher) { if (ModelState.IsValid) { _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teacher)); }
public async Task <IActionResult> Create([Bind("Id,Title,Annotation,TeacherId")] Discipline discipline) { if (ModelState.IsValid) { _context.Add(discipline); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TeacherName"] = new SelectList(_context.Teachers, "Name", "Name", _context.Teachers.Where(x => x.Id == discipline.TeacherId).Select(x => x.Name)); return(View(discipline)); }