I need to create an ApplicationUser (a derived class from IdentityUser) with my Asp.Net API, I need to create it in the same database that my Asp.net MVC uses. My request works since it gives me 200 response but my user is not in the AspNetUser table autogenerated by EntityFramework.
[HttpPost]
public async Task<ActionResult> Register(RegisterDTO register)
{
ApplicationUser user = new ApplicationUser();
if (register.Password == register.PasswordConfirm)
{
user.UserName = register.Email;
user.Email = register.Email;
}
else
{
return StatusCode(StatusCodes.Status500InternalServerError, new { Message = "Le mot de passe et sa confirmation ne sont pas identiques." });
}
var identityResult = await userManager.CreateAsync(user, register.Password);
if (!identityResult.Succeeded)
{
return StatusCode(StatusCodes.Status500InternalServerError, new { Error = identityResult.Errors });
}
return Ok();
}
this is my register from my api
services.AddDbContext<CegesDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped<ICegesServices, CegesServices>();
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddDefaultTokenProviders().AddDefaultUI()
.AddEntityFrameworkStores<CegesDbContext>();
this is the startup from my api
public class ApplicationUser : IdentityUser
{
public List<Entreprise> Entreprises { get; set; }
}
this is my ApplicationUser class in the Core project
I'm not sure what to do here. Do I need to create my on Create method for my ApplicationUser or am I missing something?