public static UserApiModel FromDomainModel(User user) { return new UserApiModel { Id = user.Id, Username = user.Username }; }
public async Task UpdateUser(User user) { var applicationUser = ApplicationUser.FromUser(user); var result = await this.userManager.UpdateAsync(applicationUser); if (!result.Succeeded) { throw new InvalidOperationException("There was an error updating the user"); } }
public async Task AddUser(User user) { var applicationUser = ApplicationUser.FromUser(user); var result = await this.userManager.CreateAsync(applicationUser); if (!result.Succeeded) { // TODO: change to identity create exception throw new Exception("There was an error adding the user"); } }
internal static ApplicationUser FromUser(User user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var applicationUser = new ApplicationUser { Id = user.Id, UserName = user.Username }; foreach (var claim in user.Claims) { applicationUser.Claims.Add(new IdentityUserClaim<string>() { ClaimType = claim.Type, ClaimValue = claim.Value }); } return applicationUser; }