public async Task <IActionResult> PostSendCheckingAccountTransaction(CancellationToken token, [FromBody] int Requests) { Random rnd = new Random(); try { AddCheckingAccountTransactionCommand AddCheckingAccountTransactionCommand = new AddCheckingAccountTransactionCommand() { CreditCheckingAccount = Guid.Parse("63F400DF-D01A-46E0-960A-5465A86C62BF"), DebitCheckingAccount = Guid.Parse("22c3f8d0-5cb9-4d29-a300-52c0adc27704"), CurrencyTypeID = Guid.Parse("6B577276-DDC9-4C8E-896A-EEE8396EFF82"), Value = rnd.Next(1, 9999999) }; var request = _requestClient.Create(AddCheckingAccountTransactionCommand, token, TimeSpan.FromMilliseconds(600)); var response = await request.GetResponse <TransportEntity>(); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <TransportEntity> InternalTransaction(AddCheckingAccountTransactionCommand Command) { try { if (Command.CreditCheckingAccount == Command.DebitCheckingAccount) { ObjReturn.Sucess = false; ObjReturn.Messages.Add("Conta de Debito e Credito iguais"); return(ObjReturn); } if (Command.Value <= 0) { ObjReturn.Sucess = false; ObjReturn.Messages.Add("Valor deve ser maior que 0"); return(ObjReturn); } Aggregates.CheckingAccount DebitCheckingAccount = await ValidatedCheckingAccount(Command.DebitCheckingAccount); if (DebitCheckingAccount.Active.Equals(false)) { ObjReturn.Sucess = false; ObjReturn.Messages.Add("Conta de Debito invalidas"); return(ObjReturn); } Aggregates.CheckingAccount CreditCheckingAccount = await ValidatedCheckingAccount(Command.CreditCheckingAccount); if (CreditCheckingAccount.Active.Equals(false)) { ObjReturn.Sucess = false; ObjReturn.Messages.Add("Conta de Credito invalidas"); return(ObjReturn); } if (Command.Value > GetBalance(Command.DebitCheckingAccount)) { ObjReturn.Sucess = false; ObjReturn.Messages.Add("Saldo Insuficiente"); return(ObjReturn); } Guid TracedID = Guid.NewGuid(); IEnumerable <CheckingAccountTransaction> TransactionList = new List <CheckingAccountTransaction>() { new CheckingAccountTransaction() { ID = Guid.NewGuid(), TracedID = TracedID, CheckingAccount = DebitCheckingAccount, Value = (Command.Value * -1), CheckingAccountTransactionStatus = await checkingAccountTransactionStatusRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionStatusEnum.Authorized), true), CheckingAccountTransactionType = await checkingAccountTransactionTypeRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionTypeEnum.InternalTransfer), true), CurrencyType = await currencyRepository.GetAsync(w => w.Code.Equals((int)CurrencyEnum.BRL), true) }, new CheckingAccountTransaction() { ID = Guid.NewGuid(), TracedID = TracedID, CheckingAccount = CreditCheckingAccount, Value = Command.Value, CheckingAccountTransactionStatus = await checkingAccountTransactionStatusRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionStatusEnum.Authorized), true), CheckingAccountTransactionType = await checkingAccountTransactionTypeRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionTypeEnum.InternalTransfer), true), CurrencyType = await currencyRepository.GetAsync(w => w.Code.Equals((int)CurrencyEnum.BRL), true) } }; await checkingAccountTransactionRepository.AddRangeAsync(TransactionList); ObjReturn.Sucess = true; ObjReturn.Data = true; return(ObjReturn); } catch (Exception ex) { ObjReturn.Sucess = false; ObjReturn.Messages.Add(ex.Message); return(ObjReturn); } }
public async Task <IActionResult> AddCheckingAccountInternalTransaction(AddCheckingAccountTransactionCommand command) { return(Ok(await mediator.Send(command))); }