public async Task <IActionResult> Post([FromBody] RegisterViewModel model) { if (ModelState.IsValid) { var user = new TransferUser { UserName = model.userName, Name = model.firstName + ' ' + model.lastName, PhoneNumber = model.phoneNumber, Email = model.email, Country = model.country }; var result = await userManager.CreateAsync(user, model.password); if (result.Succeeded) { await signInManager.SignInAsync(user, false); return(Ok(user)); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(BadRequest()); }
public User Map(TransferUser transferUser) { if (transferUser == null) { return(null); } return(new User { UserId = transferUser.UserId, Login = transferUser.Login, PrompterStatus = transferUser.PrompterStatus, Password = transferUser.Password, Disabled = transferUser.Disabled, RoleId = transferUser.RoleId, EntityState = transferUser.EntityState, //Role = _roleMapper.Map(transferUser.Role) }); }
public User Map(TransferUser transferUser) { if (transferUser == null) { return null; } return new User { UserId = transferUser.UserId, Login = transferUser.Login, PrompterStatus = transferUser.PrompterStatus, Password = transferUser.Password, Disabled = transferUser.Disabled, RoleId = transferUser.RoleId, EntityState = transferUser.EntityState, //Role = _roleMapper.Map(transferUser.Role) }; }
public async Task Seed() { ctx.Database.EnsureCreated(); if (ctx.Vehicles.Count() == 0) { ctx.Vehicles.Add( new Vehicle { Name = "Auto1", Note = "poyy", RegistrationDate = DateTime.Now, PlateNumber = "12321" }); } ctx.SaveChanges(); if (ctx.Partners.Count() == 0) { ctx.Partners.Add( new Partner { Name = "Partner Prvi", Phone = "3456787", Email = "*****@*****.**", VehicleId = 1 }); } ctx.SaveChanges(); bool x = await roleManager.RoleExistsAsync("Admin"); if (!x) { var role = new IdentityRole(); role.Name = "Admin"; await roleManager.CreateAsync(role); } ctx.SaveChanges(); var user = await userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new TransferUser() { Name = "Admin", UserName = "******", Email = "*****@*****.**" }; var result = await userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Failed To create default admin user"); } else if (result.Succeeded) { var result1 = await userManager.AddToRoleAsync(user, "Admin"); } } // user2 has no roles var user2 = await userManager.FindByEmailAsync("*****@*****.**"); if (user2 == null) { user2 = new TransferUser() { Name = "Test2", UserName = "******", Email = "*****@*****.**" }; var result = await userManager.CreateAsync(user2, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Failed to create test user"); } } ctx.SaveChanges(); }