public bool changeTransaction(TransactionPresentation tp) { var thisAcc = workableAccNmBr(tp.fromAccount); var toAcc = workableAccNmBr(tp.toAccount); try { using (var db = new ModelContext()) { Account toThisAccount = db.Accounts.FirstOrDefault (a => a.accountNumber == toAcc); Account fromThisAccount = db.Accounts.FirstOrDefault (a => a.accountNumber == thisAcc); Transaction updatedTransaction = db.Transactions.FirstOrDefault(t => t.tID == tp.ID); updatedTransaction.fromAccount = fromThisAccount; updatedTransaction.toAccount = toThisAccount; updatedTransaction.amount = tp.amount; updatedTransaction.message = tp.message; updatedTransaction.date = Convert.ToDateTime(tp.date); db.SaveChanges(); return(true); } } catch (Exception error) { logErrorToFile(error); return(false); } }
public ActionResult RegisterPayment(TransactionPresentation tp) { if (Validate.validateTransaction(tp) && tranBLL.registerTransaction(tp)) { return(View("Overview")); } return(null); }
public bool registerTransaction(TransactionPresentation tp) { if (Validate.validateTransaction(tp) && tranBLL.registerTransaction(tp)) { return(true); } return(false); }
public string editPayment(TransactionPresentation tp) { if (Validate.validateTransaction(tp)) { return(new JavaScriptSerializer().Serialize(tranBLL.changeTransaction(tp))); } return(new JavaScriptSerializer().Serialize("error")); }
public static bool validateTransaction(TransactionPresentation tp) { var a = tp.ID >= 0; var b = validateDate(tp.date); var c = validateMessage(tp.message); var d = tp.amount > 0; var e = validateAccountNmbr(tp.fromAccount); var f = validateAccountNmbr(tp.toAccount); return(a && b && c && d && e && f); }
public void listTransactions_checkAllTransactions() { // Arrange var controller = new AdminController(new AdminBLL(db), new AccountBLL(db)); var expectedResult = new List <TransactionPresentation>(); var transaction1 = new TransactionPresentation(); var transaction2 = new TransactionPresentation(); var transaction3 = new TransactionPresentation(); transaction1.ID = 1; transaction1.date = "07.11.2016"; transaction1.amount = 100.00; transaction1.message = "This is the first transaction"; transaction1.toAccount = "22222222222"; transaction1.fromAccount = "11111111111"; expectedResult.Add(transaction1); // Second transaction transaction2.ID = 2; transaction2.date = "07.11.2016"; transaction2.amount = 200.00; transaction2.message = "This is the second transaction"; transaction2.toAccount = "33333333333"; transaction2.fromAccount = "22222222222"; expectedResult.Add(transaction2); // Thirs transaction transaction3.ID = 3; transaction3.date = "07.11.2016"; transaction3.amount = 300.00; transaction3.message = "This is the third transaction"; transaction3.toAccount = "44444444444"; transaction3.fromAccount = "33333333333"; expectedResult.Add(transaction3); // Act List <TransactionPresentation> result = controller.listTransactions(false); // Assert for (var i = 0; i < result.Count; i++) { Assert.AreEqual(expectedResult[i].ID, result[i].ID); Assert.AreEqual(expectedResult[i].date, result[i].date); Assert.AreEqual(expectedResult[i].amount, result[i].amount); Assert.AreEqual(expectedResult[i].message, result[i].message); Assert.AreEqual(expectedResult[i].toAccount, result[i].toAccount); Assert.AreEqual(expectedResult[i].fromAccount, result[i].fromAccount); } }
public bool registerTransaction(TransactionPresentation inTransaction) { var thisAcc = inTransaction.fromAccount; var toAcc = inTransaction.toAccount; thisAcc = workableAccNmBr(thisAcc); toAcc = workableAccNmBr(toAcc); try { using (var db = new ModelContext()) { Account fromThisAccount = db.Accounts.FirstOrDefault (a => a.accountNumber == thisAcc); if (fromThisAccount == null) { return(false); } Account toThisAccount = db.Accounts.FirstOrDefault (a => a.accountNumber == toAcc); if (toThisAccount.active != true) { return(false); } Transaction newTransaction = new Transaction() { date = Convert.ToDateTime(inTransaction.date), toAccount = toThisAccount, amount = inTransaction.amount, message = inTransaction.message, isTransferred = false, fromAccount = fromThisAccount }; //fromAccount.transaction = new List<Transaction>(); db.Transactions.Add(newTransaction); db.SaveChanges(); return(true); } } catch (Exception error) { logErrorToFile(error); return(false); } }
public List <TransactionPresentation> listTransactions(string accountNumber, int inMonth, int inYear, bool isTransferred) { accountNumber = workableAccNmBr(accountNumber); DateTime startDate, endDate; startDate = new DateTime(inYear, inMonth, 1); endDate = new DateTime(inYear, inMonth, DateTime.DaysInMonth(inYear, inMonth)); List <Transaction> allTransactions; List <TransactionPresentation> someTransactions = new List <TransactionPresentation>(); try { using (var db = new ModelContext()) { var query = from t in db.Transactions where t.fromAccount.accountNumber == accountNumber && t.isTransferred == isTransferred && t.date <= endDate && t.date >= startDate select t; allTransactions = query.ToList(); foreach (Transaction t in allTransactions) { TransactionPresentation transactionPresentation = new TransactionPresentation() { ID = t.tID, date = t.date.ToShortDateString(), amount = t.amount, message = t.message, toAccount = readableAccNmBr(t.toAccount.accountNumber) }; someTransactions.Add(transactionPresentation); } } return(someTransactions); } catch (Exception error) { logErrorToFile(error); return(null); } }
public List <TransactionPresentation> listTransactions(bool isTransferred) { try { DateTime today = DateTime.Today; List <TransactionPresentation> allTransactions = new List <TransactionPresentation>(); List <Transaction> someTransactions; using (var db = new ModelContext()) { someTransactions = db.Transactions .Where(t => t.date <= today && t.isTransferred == isTransferred) .ToList(); if (someTransactions.Count == 0) { return(null); } foreach (var t in someTransactions) { TransactionPresentation tp = new TransactionPresentation() { ID = t.tID, date = t.date.ToShortDateString(), amount = t.amount, message = t.message, toAccount = readableAccNmBr(t.toAccount.accountNumber), fromAccount = readableAccNmBr(t.fromAccount.accountNumber) }; allTransactions.Add(tp); } return(allTransactions); } } catch (Exception error) { logErrorToFile(error); return(null); } }
/* * Returning a list of TransactionPresentation with three Transactions. * */ public List <TransactionPresentation> listTransactions(bool isTransferred) { List <TransactionPresentation> tpList = new List <TransactionPresentation>(); TransactionPresentation tp1 = new TransactionPresentation(); TransactionPresentation tp2 = new TransactionPresentation(); TransactionPresentation tp3 = new TransactionPresentation(); // First transaction tp1.ID = 1; tp1.date = "07.11.2016"; tp1.amount = 100.00; tp1.message = "This is the first transaction"; tp1.toAccount = "22222222222"; tp1.fromAccount = "11111111111"; tpList.Add(tp1); // Second transaction tp2.ID = 2; tp2.date = "07.11.2016"; tp2.amount = 200.00; tp2.message = "This is the second transaction"; tp2.toAccount = "33333333333"; tp2.fromAccount = "22222222222"; tpList.Add(tp2); // Thirs transaction tp3.ID = 3; tp3.date = "07.11.2016"; tp3.amount = 300.00; tp3.message = "This is the third transaction"; tp3.toAccount = "44444444444"; tp3.fromAccount = "33333333333"; tpList.Add(tp3); return(tpList); }
/* * Not part of obligatory #2 */ public bool registerTransaction(TransactionPresentation inTransaction) { throw new NotImplementedException(); }
/* * Not part of obligatory #2 */ public bool changeTransaction(TransactionPresentation tp) { throw new NotImplementedException(); }
public bool changeTransaction(TransactionPresentation tp) { return(db.changeTransaction(tp)); }
public bool registerTransaction(TransactionPresentation inTransaction) { return(db.registerTransaction(inTransaction)); }