コード例 #1
0
        public async Task <User> CreateAsync(UserBase model)
        {
            model.ValidateIsNotNull(nameof(model));

            var entity = new Entities.User();

            UpdateEntity(model, entity);

            await _genericRepository.InsertAsync(entity);

            await _databaseScope.SaveChangesAsync();

            return(_mapper.Map <User>(entity));
        }
コード例 #2
0
        public async Task <User> RegisterAsync(UserBase model)
        {
            model.ValidateIsNotNull(nameof(model));
            var userExists = await UserExistsAsync(model.Username);

            var emailInUse = await EmailInUseAsync(model.Email);

            if (userExists || emailInUse)
            {
                return(null);
            }

            var passwordSalt = CryptographyService.CreateSalt();
            var passwordHash = CryptographyService.CreateHash(model.Password, passwordSalt);

            var entity = new Entities.User();

            entity.PasswordHash = passwordHash;
            entity.PasswordSalt = passwordSalt;
            entity.FirstName    = model.FirstName;
            entity.LastName     = model.LastName;
            entity.Username     = model.Username;

            entity.DateOfBirth = model.DateOfBirth;
            entity.Email       = model.Email;

            await _genericRepository.InsertAsync(entity);

            await _databaseScope.SaveChangesAsync();

            return(_mapper.Map <User>(entity));
        }