コード例 #1
0
        public async Task <RequestResult <Fibonacci> > Create(Fibonacci fibonacci, CancellationToken cancellationToken)
        {
            var requestResult   = new RequestResult <Fibonacci>();
            var entityFibonacci = _iMapper.Map <EntityFibonacci>(fibonacci);

            await _iRepoBase.Create(entityFibonacci, cancellationToken);

            requestResult.Model = _iMapper.Map <Fibonacci>(entityFibonacci);

            return(requestResult);
        }
コード例 #2
0
        public async Task <RequestResult <RefreshToken> > Create(int userId, CancellationToken cancellationToken)
        {
            var requestResult = new RequestResult <RefreshToken>();

            var entityRefreshToken = new EntityRefreshToken
            {
                UserId = userId,

                Token = CreateToken(),
            };

            await _iRepoBase.Create(entityRefreshToken, cancellationToken);

            requestResult.Model = _iMapper.Map <RefreshToken>(entityRefreshToken);

            return(requestResult);
        }
コード例 #3
0
        public async Task <RequestResult <ExceptionLog> > Create(CancellationToken cancellationToken, ExceptionLog exceptionLog, string applicationName)
        {
            var requestResult = new RequestResult <ExceptionLog>();

            var entityExceptionLog = _iMapper.Map <EntityExceptionLog>(exceptionLog);

            entityExceptionLog.ApplicationName = applicationName;
            entityExceptionLog.CreatedDateUtc  = DateTime.UtcNow;

            if (entityExceptionLog.InnerException != null)
            {
                entityExceptionLog.InnerException.CreatedDateUtc = DateTime.UtcNow;
            }

            await _iRepoBase.Create(entityExceptionLog, cancellationToken);

            requestResult.Model = _iMapper.Map <ExceptionLog>(entityExceptionLog);

            return(requestResult);
        }
コード例 #4
0
        public async Task <RequestResult <Fibonacci> > Create(Fibonacci fibonacci, CancellationToken cancellationToken)
        {
            var requestResult   = new RequestResult <Fibonacci>();
            var entityFibonacci = _iMapper.Map <EntityFibonacci>(fibonacci);

            if (fibonacci.Iterations > 46)
            {
                requestResult.Errors.Add("Cannot compute for more than 46");
                entityFibonacci.Total = 0;
            }
            else
            {
                entityFibonacci.Total = FibonacciTotal(fibonacci.Iterations);
            }

            await _iRepoBase.Create(entityFibonacci, cancellationToken);

            requestResult.Model = _iMapper.Map <Fibonacci>(entityFibonacci);

            return(requestResult);
        }
コード例 #5
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);
        }
コード例 #6
0
 public void Create(T entity)
 {
     repo.Create(entity);
 }