Beispiel #1
0
        public async Task <ActionResult <AuthenticatedUser> > Register([FromBody] RegisterCredentials credentials)
        {
            var isAdded = await _users.AddUserAsync(credentials);

            if (isAdded)
            {
                var user = await _authenticateService.Authenticate(new LoginCredentials()
                {
                    Email = credentials.Email, Password = credentials.Password
                });

                if (user != null)
                {
                    var transaction = await _transactions.CreateTransactionAsync(null, user.Id, REGISTRATION_BONUS, DateTime.Now);

                    if (transaction != null)
                    {
                        var result = await _transactions.CommitTransactionAsync(transaction);

                        if (result != null)
                        {
                            return(Ok(user));
                        }
                    }
                }
                return(BadRequest(new { message = "Registration failed" }));
            }
            else
            {
                return(BadRequest(new { message = "User already registered" }));
            }
        }
        public async Task <ActionResult <Transaction> > CommitTransaction(Transaction newTransaction)
        {
            var transaction = await _transactions.GetTransactionAsync(newTransaction.Id);

            if (transaction != null && transaction.SenderId == UserId)
            {
                transaction = await _transactions.CommitTransactionAsync(transaction);

                if (transaction != null)
                {
                    return(Ok(transaction));
                }
            }

            return(BadRequest(new { message = $"Could not commit transaction" }));
        }