internal async Task PostTransaction(Transaction localTransaction) { var accountId = await GetAccountId(localTransaction.Last4); if (accountId == null) { throw new Exception($"No account found for {localTransaction.Last4}"); } _logger.LogInformation("Found account: {id}", accountId); _logger.LogDebug("Date: {date}", localTransaction?.Date); _logger.LogDebug("Amount: {amount}", localTransaction?.Amount); _logger.LogDebug("Payee: {payee_name}", localTransaction?.Payee); var request = new AddTransactionRequest { transaction = new Domain.YNAB.Transaction { account_id = accountId, date = localTransaction.Date.ToString("yyyy-MM-dd"), amount = (int)(localTransaction.Amount * -1000), payee_name = localTransaction.Payee, cleared = "uncleared", memo = "Instant Sync", } }; await _httpClient.PostAsJsonAsync("transactions", request); }
public async Task AddTransactionAsync(AddTransactionRequest request) { var entity = _mapper.Map <Entities.Transaction>(request); DbContext.Transactions.Add(entity); await DbContext.SaveChangesAsync(); }
public IActionResult Add([FromBody] TransactionAddRequest request) { if (!ModelState.IsValid) { return(this.BadRequest()); } var handlerRequest = new AddTransactionRequest(request.Amount, request.Description, request.TransactionDate, request.Tags); var result = _mediator.Send(handlerRequest); return(Ok(result)); }
public async Task <IActionResult> Add([FromBody] AddTransactionRequest request, [FromRoute] int accountId) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var response = await _transactionService.AddAsync(request, accountId); if (!response.IsValid) { return(BadRequest(response.Message)); } return(Ok(response)); }
/// <summary> /// Add a new transaction /// /// This will generate ledger transactions and update the balance for the organization / cargo type according to the transactiontype /// </summary> /// <param name="request"></param> /// <returns></returns> public AddTransactionResponse AddTransaction(AddTransactionRequest request) { try { Guard.IsNotNull(request); var response = _transactionService.AddTransaction(Mapper.Map <AddTransactionCommandRequest>(request)); if (response.ServiceStatus != TransactionService.Contracts.Models.Service.ServiceStatus.Success) { return(new AddTransactionResponse(ServiceStatus.ServiceError, response.ErrorMessage)); } Clients.All.getNewState(response); return(Mapper.Map <AddTransactionResponse>(response)); } catch (Exception ex) { _log.Error(ex.Message); return(new AddTransactionResponse(ServiceStatus.ServiceError, ex.Message)); } }
// INSERT: Transaction/AddTransaction/CreateUserRequest public bool AddTransaction([FromBody] AddTransactionRequest request) { var context = HttpContext.RequestServices.GetService(typeof(CibitDb)) as CibitDb; var verify = new ValidateUser(); var config = new MapperConfiguration(mc => mc.CreateMap <AddTransactionRequest, TransactionDTO>()); var mapper = new Mapper(config); var userinfo = mapper.Map <AddTransactionRequest, TransactionDTO>(request); if (!verify.VerifyCoinId(userinfo.CoinId, userinfo.SenderId)) { return(false); } var spObj = Converters.AddTransactionConverter(userinfo); var reader = context.StoredProcedureSql("AddTransaction", spObj); context.Connection.Close(); return(true); }
public async Task <BaseResponse> AddAsync(AddTransactionRequest request, int accountId) { var category = await _categoryRepository.GetAsync(category => category.Id == request.CategoryId && category.AccountId == accountId); if (category == null) { return(new ResultResponse <TransactionDto>("Category is not found")); } if (request.TagId.HasValue) { var tag = await _tagRepository.GetAsync(tag => tag.Id == request.TagId); if (tag == null) { return(new ResultResponse <TransactionDto>("Tag is not found")); } } if (request.SpentById.HasValue) { var spentBy = await _accountUserRepository.GetAsync(accountUser => accountUser.Id == request.SpentById); if (spentBy == null) { return(new ResultResponse <TransactionDto>("Account user is not found")); } } var transaction = _mapper.Map <AddTransactionRequest, Transaction>(request); var loggedUser = await _authenticationService.GetLoggedUserAsync(); var accountUser = await _accountUserRepository.GetAsync(accountUser => accountUser.UserId == loggedUser.User.Id && accountUser.AccountId == category.AccountId); transaction.CreatedBy = accountUser; await _transactionRepository.AddAsync(transaction); await _unitOfWork.SaveChangesAsync(); return(new BaseResponse()); }
public ActionResult <OpenAccountResponse> Post([FromBody] AddTransactionRequest addTransactionRequest) { if (addTransactionRequest == null || string.IsNullOrEmpty(addTransactionRequest.CustomerID)) { return(BadRequest(new AddTransactionResponse { Request = addTransactionRequest, ReturnDescription = Constants.NOT_A_VALID_INPUT })); } Dictionary <string, List <Model.Transaction> > transactionsInTheSystem = JsonConvert.DeserializeObject <Dictionary <string, List <Model.Transaction> > >(_cache.Get(Constants.TRANSACTIONS_CACHE_KEY).ToString()); var doWeHaveAnyTransactionForThisUserBefore = transactionsInTheSystem.TryGetValue(addTransactionRequest.CustomerID, out List <Model.Transaction> transactionsForThisUser); if (!doWeHaveAnyTransactionForThisUserBefore) { //We do not have any transaction belong to this user before transactionsForThisUser = new List <Model.Transaction> { addTransactionRequest.Transaction }; transactionsInTheSystem.Add(addTransactionRequest.CustomerID, transactionsForThisUser); } else { //We have already some transactions for this user //So add a new one transactionsForThisUser.Add(addTransactionRequest.Transaction); transactionsInTheSystem[addTransactionRequest.CustomerID] = transactionsForThisUser; } _cache.Set(Constants.TRANSACTIONS_CACHE_KEY, JsonConvert.SerializeObject(transactionsInTheSystem)); return(Ok(new AddTransactionResponse { ReturnDescription = Constants.OK, Request = addTransactionRequest, })); }
public async Task <AddTransactionResponse> AddTransaction(AddTransactionRequest request) { return(await Client.Execute <AddTransactionRequest, AddTransactionResponse>(request)); }
public ActionResult AddTransactions(AddTransactionRequest data) { _blockChainService.AddNewTransactions(data.Transactions, data.SenderAddress); return(Ok()); }
private async Task <AddTransactionResponse> AddTransactionRESTAPI(string url, AddTransactionRequest request) { HttpClient client = new HttpClient(); var requestBody = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url, requestBody); response.EnsureSuccessStatusCode(); var responseBody = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <AddTransactionResponse>(responseBody)); }
public AddTransactionResponse AddTransactionQuee(AddTransactionRequest request) { return(AddTransactionRESTAPI(Constants.ADD_TRANSACTION_URL, request).GetAwaiter().GetResult()); }