コード例 #1
0
 public TransactionViewModel()
 {
     JournalHeader   = new JournalHeaderViewModel();
     JournalLineItem = new JournalLineItemViewModel();
     PreviousEntries = new List <JournalLineItemViewModel>();
     Action          = null;
     EditMode        = false;
 }
コード例 #2
0
        public TransactionViewModel ConvertToTransactionViewModel(int transactionID)
        {
            string             retrieveHeader = $"SELECT * FROM [Recording].JournalTransactions WHERE TransactionID = {transactionID}";
            JournalTransaction header         = dbConnection.QueryFirstOrDefault <JournalTransaction>(retrieveHeader);

            if (header == null)
            {
                return(null);
            }

            string retrieveLineItems = $"SELECT * FROM [Recording].JournalEntries WHERE ParentTransactionID = {header.TransactionId}";
            var    lineItems         = dbConnection.Query <JournalEntry>(retrieveLineItems).ToList();

            if (lineItems == null)
            {
                return(null);
            }

            TransactionViewModel viewModel = new TransactionViewModel();

            viewModel.JournalHeader.Memo          = header.Memo;
            viewModel.JournalHeader.TransactionID = header.TransactionId;
            viewModel.DefaultEntryDate            = DateTime.Parse(header.RecordedDateTime);
            viewModel.UserID   = header.UserID;
            viewModel.EditMode = true;

            foreach (JournalEntry item in lineItems)
            {
                JournalLineItemViewModel newItem = new JournalLineItemViewModel();
                newItem.AccountName = item.AccountName;
                if (item.DebitAmount != null)
                {
                    newItem.DebitAmount = (decimal)item.DebitAmount;
                }
                else
                {
                    newItem.CreditAmount = (decimal)item.CreditAmount;
                }
                viewModel.PreviousEntries.Add(newItem);
            }
            return(viewModel);
        }