public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, Name = createUserModel.Name, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return GetErrorResult(addUserResult); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); AppUserManager.ConfirmEmail(user.Id, code); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return Created(locationHeader, TheModelFactory.Create(user)); }
public UserReturnModel Create(ApplicationUser appUser) { return new UserReturnModel { Url = _UrlHelper.Link("GetUserById", new { id = appUser.Id }), Id = appUser.Id, UserName = appUser.UserName, FullName = appUser.Name, //FullName = string.Format("{0} {1}", appUser.Name, appUser.Lastname), Email = appUser.Email, EmailConfirmed = appUser.EmailConfirmed, Password = appUser.PasswordHash, Roles = _AppUserManager.GetRolesAsync(appUser.Id).Result, Claims = _AppUserManager.GetClaimsAsync(appUser.Id).Result }; }