Example #1
0
        public IActionResult Collect(PointsTransactionAccountCommand command)
        {
            Account account = accountRepository.GetById(Guid.Parse(command.AccountId));

            if (account == null)
            {
                return(StatusCode(404, new { Message = "The account was not found." }));
            }

            if (command.Amount <= 0)
            {
                return(StatusCode(400, new { Message = "The value provided is not valid." }));
            }

            if (account.MemberId == Guid.Parse(command.MemberID))
            {
                try
                {
                    account.Balance += command.Amount;
                    accountRepository.Update(account);
                    return(Ok(new { Message = $"The amount of {command.Amount} points was collected and the new balance for this account is {account.Balance}" }));
                }
                catch (Exception e)
                {
                    return(StatusCode(500, e.Message));
                }
            }
            else
            {
                return(StatusCode(403, new { Message = "Member does not match the account" }));
            }
        }
Example #2
0
        public IActionResult Redeem(PointsTransactionAccountCommand command)
        {
            Account account = accountRepository.GetById(Guid.Parse(command.AccountId));

            if (account == null)
            {
                return(StatusCode(404, new { Message = "The account was not found." }));
            }

            if (command.Amount <= 0)
            {
                return(StatusCode(400, new { Message = "The value provided is not valid." }));
            }

            if (account.Status == AccountStatus.INACTIVE)
            {
                return(StatusCode(401, new { Message = "Inactive accounts are not subject to redeem transactions" }));
            }

            if (account.Balance - command.Amount < 0)
            {
                return(StatusCode(400, new { Message = "The value exceeds the account balance." }));
            }

            if (account.MemberId == Guid.Parse(command.MemberID))
            {
                try
                {
                    account.Balance -= command.Amount;
                    accountRepository.Update(account);
                    return(Ok(new { Message = $"The amount of {command.Amount} points was redeemed and the new balance for this account is {account.Balance}" }));
                }
                catch (Exception e)
                {
                    return(StatusCode(500, e.Message));
                }
            }
            else
            {
                return(StatusCode(403, new { Message = "Member does not match the account" }));
            }
        }