public ActionResult Create([Bind(Include = "LogID,userNameLog,transactionLog,dateLog")] LoggerModel loggermodel) { if (ModelState.IsValid) { db.Loggers.Add(loggermodel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loggermodel)); }
public ActionResult DeleteConfirmed(int id) { AccountDBContext db2 = new AccountDBContext(); UtilityBillModel utilitybillmodel = db.UtilityBills.Find(id); var accSum = from a in db2.Accounts where a.AccountID.Equals(utilitybillmodel.AccountToPayID) select a.AccountBalance; //Check if account exists if (accSum != null) { //Check if account sum is greater than the bill if (accSum.FirstOrDefault() >= utilitybillmodel.AmountToPay) //pay { var accountToUpdate = db2.Accounts.Where(o => o.AccountID == utilitybillmodel.AccountToPayID); // update LastName for all Persons in personsToUpdate foreach (BankAccountModel p in accountToUpdate) { p.AccountBalance = accSum.FirstOrDefault() - utilitybillmodel.AmountToPay; } db.UtilityBills.Remove(utilitybillmodel); db.SaveChanges(); db2.SaveChanges(); String currentUser = User.Identity.Name; db1.Loggers.Add( new LoggerModel { dateLog = DateTime.Now, userNameLog = currentUser, transactionLog = "Utility payed for " + utilitybillmodel.AccountToPayID + " for amount " + utilitybillmodel.AmountToPay } ); db1.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Error1")); } } //If account does not exist else { return(RedirectToAction("Error")); } }
public ActionResult Create([Bind(Include = "ClientID,ClientName,CNP,address")] ClientModel clientmodel) { if (ModelState.IsValid) { db.Clients.Add(clientmodel); db.SaveChanges(); String currentUser = User.Identity.Name; db1.Loggers.Add( new LoggerModel { userNameLog = currentUser, dateLog = DateTime.Now, transactionLog = "Create client: " + clientmodel.ClientName.ToString() + "\n" } ); db1.SaveChanges(); return(RedirectToAction("Index")); } return(View(clientmodel)); }
public ActionResult Create([Bind(Include = "TransactionID,AccountFromID,AccountToID,TransactionAmount,TransactionDate")] TransactionModel transactionmodel) { if (ModelState.IsValid) { var clientID1 = from a in db2.Accounts where a.AccountID.Equals(transactionmodel.AccountFromID) select a.AccountClientID; var clientID2 = from a in db2.Accounts where a.AccountID.Equals(transactionmodel.AccountToID) select a.AccountClientID; if (clientID1 != null && clientID2 != null && transactionmodel.AccountFromID != transactionmodel.AccountToID) { var AccBalance1 = from a in db2.Accounts where a.AccountID.Equals(transactionmodel.AccountFromID) select a.AccountBalance; var AccBalance2 = from a in db2.Accounts where a.AccountID.Equals(transactionmodel.AccountToID) select a.AccountBalance; if (AccBalance1.FirstOrDefault() - transactionmodel.TransactionAmount >= 0) { var accountToUpdateFrom = db2.Accounts.Where(o => o.AccountID == transactionmodel.AccountFromID); var accountToUpdateTo = db2.Accounts.Where(o => o.AccountID == transactionmodel.AccountToID); // update LastName for all Persons in personsToUpdate foreach (BankAccountModel p in accountToUpdateFrom) { p.AccountBalance = AccBalance1.FirstOrDefault() - transactionmodel.TransactionAmount; } foreach (BankAccountModel p in accountToUpdateTo) { p.AccountBalance = AccBalance2.FirstOrDefault() + transactionmodel.TransactionAmount; } db.Transactions.Add(transactionmodel); db.SaveChanges(); db2.SaveChanges(); String currentUser = User.Identity.Name; db3.Loggers.Add( new LoggerModel { userNameLog = currentUser, dateLog = DateTime.Now, transactionLog = "Transfer: " + transactionmodel.AccountFromID.ToString() + " to " + transactionmodel.AccountToID.ToString() + " amount: " + transactionmodel.TransactionAmount.ToString() + "\n" } ); db3.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Error1")); } } else { return(RedirectToAction("Error2")); } } return(RedirectToAction("Error")); }