public async Task <IActionResult> AddBill(int userId, TransactionForCreationDto TransactionForCreation) { var creator = await _userRepo.GetUser(userId); if (creator.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var Transaction = _mapper.Map <Transaction>(TransactionForCreation); Transaction.User = creator; Transaction.Reconciled = true; _repo.Add(Transaction); var AccountToForUpdate = await _repo.GetAccountByName(userId, Transaction.AccountTo); AccountToForUpdate.Balance += Transaction.Cost; if (await _repo.SaveAll()) { var jobToReturn = _mapper.Map <TransactionForReturnDto>(Transaction); return(CreatedAtRoute("GetTransaction", new { Id = Transaction.Id, userId = userId }, jobToReturn)); } throw new Exception("Creation of Transaction item failed on save"); }
public ActionResult <TransactionDto> CreateOutcomeTransaction(TransactionForCreationDto transaction) { var transactionEntity = _mapper.Map <Entities.OutcomeTransaction>(transaction); _transactionRepository.AddOutcomeTransaction(transactionEntity); _transactionRepository.Save(); var transactionToReturn = _mapper.Map <TransactionDto>(transactionEntity); return(CreatedAtRoute("GetTransaction", new { transactionId = transactionToReturn.Id }, transactionToReturn)); }
public async Task <IActionResult> Post([FromBody] TransactionForCreationDto transactionForCreationDto) { var agrFromRepo = await this._agreementRepo.GetSingle(transactionForCreationDto.AgreementId); if (agrFromRepo == null) { return(BadRequest()); } var tr = new Transaction { AgreementId = transactionForCreationDto.AgreementId, AmountPaid = transactionForCreationDto.AmountPaid }; var result = await _transactionRepo.Create(tr); var incomeDto = _mapper.Map <TransactionDto>(tr); return(Ok(incomeDto)); }
public PerformAccountTransactionCommand(TransactionForCreationDto transactionForCreationDto) { TransactionForCreationDto = transactionForCreationDto; }