Пример #1
0
 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;
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="roleId">default is 2 - SetLocaleRole.Developer.Value </param>
        /// <returns></returns>
        public async Task<long?> Create(UserModel model, int roleId = 2)
        {
            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,
                RoleName = SetLocaleRole.GetString(roleId),
                IsActive = true,
                Language = model.Language
            };
            _userRepo.Create(user);

            if (!_userRepo.SaveChanges()) return null;

            return await Task.FromResult(user.Id);
        }