コード例 #1
0
 public static UserApiModel FromDomainModel(User user)
 {
     return new UserApiModel
     {
         Id = user.Id,
         Username = user.Username
     };
 }
コード例 #2
0
 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");
     }
 }
コード例 #3
0
 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");
     }
 }
コード例 #4
0
        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;    
        }