Пример #1
0
        public async Task <RequestResult> Delete(int userId, CancellationToken cancellationToken)
        {
            var requestResult = new RequestResult <RefreshToken>();

            var hasRefreshTokens = await _iRepoBase.Exists <EntityRefreshToken>(a => a.UserId == userId, cancellationToken);

            if (hasRefreshTokens)
            {
                await _iRepoBase.Delete <EntityRefreshToken>(a => a.UserId == userId, cancellationToken);
            }

            return(requestResult);
        }
Пример #2
0
        public async Task <RequestResult <User> > Create(User user, CancellationToken cancellationToken)
        {
            var requestResult = new RequestResult <User>();

            var usernameExists = await _iRepoBase.Exists <EntityUser>(a => a.Username == user.Username, cancellationToken);

            if (!usernameExists)
            {
                var entityUser = _iMapper.Map <EntityUser>(user);
                entityUser.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);

                await _iRepoBase.Create(entityUser, cancellationToken);

                entityUser.Password = string.Empty;
                requestResult.Model = _iMapper.Map <User>(entityUser);
            }
            else
            {
                requestResult.Errors.Add("Username already exists");
            }

            return(requestResult);
        }