public static UserModel MapUserToUserModel(User user) { var model = new UserModel { Email = user.Email, Id = user.Id, Name = user.Name, RoleName = user.RoleName, Language = user.Language, IsActive = user.IsActive, RoleId = user.RoleId }; return model; }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="roleId">default is 3 - SetLocaleRole.Developer.Value </param> /// <returns></returns> public async Task<int?> Create(UserModel model, int roleId = 3) { var img = GravatarHelper.GetGravatarURL(model.Email, 55, "mm"); var user = new User { Email = model.Email, Name = model.Name, PasswordHash = BCrypt.Net.BCrypt.HashPassword(model.Password), ImageUrl = img, RoleId = roleId, IsActive = true, Language = model.Language }; _userRepo.Create(user); if (!_userRepo.SaveChanges()) return null; return await Task.FromResult(user.Id); }