コード例 #1
0
        public bool CreateLoginForUser(UserDto user)
        {
            var existingUser = _dalContext.GetUserByNameAndEmail(user.Name, user.Email);

            var successful = UserPassesAgeCheck(user);

            if (existingUser == null)
            {
                user.Logins.Single().Successful = successful;
                _dalContext.Users.Add(UserFactory.CreateUser(user));
            }

            else
            {
                var login = LoginFactory.CreateLogin(user.Logins.Single());
                login.User       = existingUser;
                login.Successful = successful;
                _dalContext.Logins.Add(login);
            }

            _dalContext.SaveChanges();

            if (successful)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public static User CreateUser(UserDto userDto)
        {
            var user = new User
            {
                Name        = userDto.Name,
                Email       = userDto.Email,
                DateOfBirth = userDto.DateOfBirth
            };

            if (userDto.Logins?.Count > 0)
            {
                user.Logins = new List <Login>();
                foreach (var loginDto in userDto.Logins)
                {
                    var login = LoginFactory.CreateLogin(loginDto);
                    user.Logins.Add(login);
                }
            }

            return(user);
        }