Exemplo n.º 1
0
        public IHttpActionResult GetClientsWithQuota()
        {
            try
            {
                using (DB_FleetServiceEntities db = new DB_FleetServiceEntities())
                {
                    var lsFinancialInformation = db.STRPRC_GET_FINANCIAL_INFORMATION_BY_CLIENT();
                    List <FinancialInformationViewModel> lsFinancialInformationByClient = new List <FinancialInformationViewModel>();
                    foreach (var financialInformationByClient in lsFinancialInformation)
                    {
                        FinancialInformationViewModel finantialInformation = new FinancialInformationViewModel();

                        var clientTmp = new ClientViewModel();
                        clientTmp.id        = financialInformationByClient.cli_id;
                        clientTmp.document  = financialInformationByClient.cli_document;
                        clientTmp.name      = financialInformationByClient.cli_name;
                        clientTmp.phone     = financialInformationByClient.cli_phone;
                        clientTmp.cellphone = financialInformationByClient.cli_cellphone;
                        clientTmp.website   = financialInformationByClient.cli_website;
                        clientTmp.city      = (financialInformationByClient.cty_id != null) ? new CityViewModel {
                            id = financialInformationByClient.cty_id
                        } : null;

                        finantialInformation.client         = clientTmp;
                        finantialInformation.approvedQuota  = double.Parse(financialInformationByClient.ficl_approvedQuota.ToString());
                        finantialInformation.currentQuota   = double.Parse(financialInformationByClient.ficl_currentQuota.ToString());
                        finantialInformation.consumedQuota  = double.Parse(financialInformationByClient.ficl_consumedQuota.ToString());
                        finantialInformation.inTransitQuota = double.Parse(financialInformationByClient.ficl_inTransitQuota.ToString());

                        lsFinancialInformationByClient.Add(finantialInformation);
                    }
                    return(Ok(lsFinancialInformationByClient));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        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));
            }
        }