コード例 #1
0
        public IActionResult UpdateTransaction(Guid transactionId, TransactionForUpdateDto transaction)
        {
            if (!_transactionRepository.IncomeTransactionExists(transactionId) && !_transactionRepository.OutcomeTransactionExists(transactionId))
            {
                return(NotFound());
            }

            var incomeTransactionFromRepo  = _transactionRepository.GetIncomeTransaction(transactionId);
            var outcomeTransactionFromRepo = _transactionRepository.GetOutcomeTransaction(transactionId);

            if (incomeTransactionFromRepo != null)
            {
                _mapper.Map(transaction, incomeTransactionFromRepo);
            }

            if (outcomeTransactionFromRepo != null)
            {
                _mapper.Map(transaction, outcomeTransactionFromRepo);
            }

            _transactionRepository.Save();
            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateTransaction(int userId, int Id, TransactionForUpdateDto TransactionForUpdateDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var TransactionFromRepo = await _repo.GetTransaction(Id);

            _mapper.Map(TransactionForUpdateDto, TransactionFromRepo);

            if (TransactionFromRepo.AccountFrom != null && TransactionFromRepo.AccountTo != null)
            {
                TransactionFromRepo.Reconciled = true;
            }

            if (await _repo.SaveAll())
            {
                return(CreatedAtRoute("GetTransaction", new { Id = TransactionFromRepo.Id, userId = userId }, TransactionFromRepo));
            }

            throw new Exception($"Updating Transaction item {Id} failed on save");
        }