public async Task <IActionResult> Log() { var user = await _userManager.FindByNameAsync(_userManager.GetUserName(User)); var databaseList = await _ctx.Transactions.Where(t => t.User == user).ToListAsync(); var transactions = new List <LogTransactionViewModel>(); foreach (var transaction in databaseList) { var newTransaction = new LogTransactionViewModel(transaction); transactions.Add(newTransaction); } return(View(transactions)); }
public IHttpActionResult GetTransactionsByClient(int client_id) { try { using (DB_FleetServiceEntities db = new DB_FleetServiceEntities()) { var lsLogtransaction = db.STRPRC_GET_TRANSACTIONS_BY_CLIENT(client_id); var lsLogTrx = new List <LogTransactionViewModel>(); foreach (var trx in lsLogtransaction) { TransactionViewModel logTrx = new TransactionViewModel(); logTrx.id = trx.trx_id; logTrx.consecutive = trx.trx_consecutive; logTrx.value = (double)trx.trx_value; logTrx.registrationDate = trx.trx_registrationDate; logTrx.movement = new MovementViewModel(); logTrx.movement.id = trx.m_id; logTrx.movement.name = trx.m_name; if (trx.trxst_id != null) { logTrx.transactionState = new TransactionStateViewModel(); logTrx.transactionState.id = trx.trxst_id; logTrx.transactionState.name = trx.trxst_name; } logTrx.headerDetails = new TransactionDetailViewModel(); if (trx.deal_id != null) { logTrx.headerDetails.dealer = new DealerViewModel(); logTrx.headerDetails.dealer.id = trx.deal_id; logTrx.headerDetails.dealer.name = trx.deal_name; } if (trx.bra_id != null) { logTrx.headerDetails.branch = new BranchViewModel(); logTrx.headerDetails.branch.id = trx.bra_id; logTrx.headerDetails.branch.name = trx.bra_name; } FinancialInformationViewModel initValues = new FinancialInformationViewModel(); initValues.currentQuota = (double)trx.ltrx_initCurrentQuota; initValues.consumedQuota = (double)trx.ltrx_initConsumedQuota; initValues.inTransitQuota = (double)trx.ltrx_initInTransitQuota; FinancialInformationViewModel endValues = new FinancialInformationViewModel(); endValues.currentQuota = (double)trx.ltrx_endCurrentQuota; endValues.consumedQuota = (double)trx.ltrx_endConsumedQuota; endValues.inTransitQuota = (double)trx.ltrx_endInTransitQuota; LogTransactionViewModel logTransaction = new LogTransactionViewModel(); logTransaction.transaction = logTrx; logTransaction.initValues = initValues; logTransaction.endValues = endValues; lsLogTrx.Add(logTransaction); } return(Ok(lsLogTrx)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }