shawnwildermuth / DualAuthCore

An example of using Dual Authorization in ASP.NET COre 2
Apache License 2.0
101 stars 37 forks source link

Problem in create Register page asp.net core 3.1 #7

Closed tarek4489 closed 4 years ago

tarek4489 commented 4 years ago

The error

wer

The code

public class SetorsController : Controller { private readonly ApplicationDbContext _context; private ApplicationDbContext context;

    public SetorsController(ApplicationDbContext context)
    {
        this.context = context;
    }

    // GET: Admin/Setors
    [HttpGet]
    public async Task<IActionResult> Cadastrar()
    {
        RegisterViewModel model = new RegisterViewModel()
        {
            SetoresList = await context.Setores.ToListAsync(),
            UnidadesList = await context.Unidades.ToListAsync()
        };

        return View();
    }

    private readonly UserManager<IdentityUser> userManager;
    private readonly SignInManager<IdentityUser> signInManager;

    public SetorsController(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
    {
        this.userManager = userManager;
        this.signInManager = signInManager;
    }

    private RegisterViewModel RegisterViewModel()
    {
        throw new NotImplementedException();
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Cadastrar(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = new IdentityUser { UserName = model.Email, Email = model.Email };
            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await signInManager.SignInAsync(user, isPersistent: false);
                return RedirectToAction("index", "home");
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }
        }
        return View(model);
    }
shawnwildermuth commented 4 years ago

Get new source, should be fixed now.