public UserReturnModel Create(ApplicationUser appUser) { return new UserReturnModel { Url = _UrlHelper.Link("GetUserById", new { id = appUser.Id }), Id = appUser.Id, UserName = appUser.UserName, FullName = string.Format("{0}", appUser.FullName), Email = appUser.Email, EmailConfirmed = appUser.EmailConfirmed, Roles = _AppUserManager.GetRolesAsync(appUser.Id).Result, Claims = _AppUserManager.GetClaimsAsync(appUser.Id).Result }; }
public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, FullName = createUserModel.FullName, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return GetErrorResult(addUserResult); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); try { await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", @"Please confirm your account by clicking <a href="" + callbackUrl"" + "">here</a>"); } catch(Exception ex) { return Ok("Email not sent :" + ex); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return Created(locationHeader, TheModelFactory.Create(user)); // return Ok(); }