public TransactionViewModel() { JournalHeader = new JournalHeaderViewModel(); JournalLineItem = new JournalLineItemViewModel(); PreviousEntries = new List <JournalLineItemViewModel>(); Action = null; EditMode = false; }
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); }