Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Name,Group")] Student student)
        {
            if (ModelState.IsValid)
            {
                // register new user
                var user = new IdentityUser {
                    UserName = student.Name, Email = $"{student.Name}@gmail.com"
                };

                var result = await _userManager.CreateAsync(user, "!1Tempo");

                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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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["TeacherId"] = new SelectList(_context.Teachers, "Id", "Name", discipline.TeacherId);
            return(View(discipline));
        }