示例#1
0
 private UserDto GetUserDto(User user, UserDetails userDetails)
 {
     return new UserDto()
     {
         UserId = user.UserId,
         UserState = GetUserState(user.UserState),
         Age = userDetails.Age,
         Height = userDetails.Height,
         Login = user.UserName,
         Email = user.Email,
         Password = null,
         PasswordConfirmation = null,
         Weight = userDetails.Weight,
         Gender = userDetails.Gender,
         IsAdministrator = user.Administrator
     };
 }
示例#2
0
        public void RegisterUser(String username, String email, String password, Int32 gender, Decimal height, Decimal weight, Int32 age)
        {
            using (var trans = context.Database.BeginTransaction())
            {
                CheckUsername(username);
                CheckEmail(email);
                CheckAge(age);
                CheckGender(gender);

                var salt = CreateSalt(32);
                byte[] pass = Encoding.UTF8.GetBytes(password);
                var hash = GenerateSaltedHash(pass, salt);

                Guid userId = Guid.NewGuid();

                var user = new User()
                {
                    UserId = userId,
                    UserState = 0,
                    UserName = username,
                    HashCode = Convert.ToBase64String(hash),
                    Salt = Convert.ToBase64String(salt),
                    Email = email,
                    Administrator = false
                };

                var userDetails = new UserDetails()
                {
                    UserId = userId,
                    Gender = gender,
                    Height = height,
                    Weight = weight,
                    Age = age
                };

                userDetails.User = user;
                context.UsersDetails.Add(userDetails);
                context.SaveChanges();
                trans.Commit();
            }
        }