public ActionResult TransferMoneyToCard(FormCollection form) { Client client = LogInInfo.LoggedInClient(); string bankId = form["BankId"]; string cardId = form["CardId"]; int sum; try { sum = int.Parse(form["Sum"]); } catch (FormatException) { ViewBag.Result = Message.WrongSum; return View(); } if (client == null) { return RedirectToAction("LogIn", "Account"); } if (client.State.CardId != cardId || client.State.BankId != bankId) { ViewBag.Result = Message.WrongId; return View(); } if (sum <= 0 || sum > 100000000) { ViewBag.Result = Message.SumIntervalMismatch; return View(); } if (sum > client.State.BankMoney) { ViewBag.Result = Message.NotEnoughBankMoney; return View(); } MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.TrasferMoneyToCard(sum); Operation operation = new Operation(DateTime.Now, client.Id, "Transfer", client.State.BankId, String.Empty, String.Empty, client.State.CardId, sum); _clientsRepository.SaveObject(client); LogInInfo.UpdateLoggedInClient(); _operationsRepository.SaveObject(operation); ViewBag.Result = Message.OperationSuccessed; return View(); }
public ActionResult TransferMoneyFromBankIdToBankId(FormCollection form) { Client client = LogInInfo.LoggedInClient(); string bankId = form["BankId"]; string bankIdTo = form["BankIdTo"]; int sum; try { sum = int.Parse(form["Sum"]); } catch (FormatException) { ViewBag.Result = Message.WrongSum; return View(); } List<Client> list = _clientsRepository.Objects.ToList(); Client clientTo = null; try { clientTo = list.First(p => String.CompareOrdinal(p.State.BankId, bankIdTo) == 0); } catch (InvalidOperationException) { if (client == null) { return RedirectToAction("Login", "Account"); } if (client.State.BankId != bankId) { ViewBag.Result = string.Format("Bank Id {0}", Message.WrongField); return View(); } if (clientTo == null) { ViewBag.Result = string.Format("Bank Id To {0}", Message.WrongField); return View(); } } if (sum <= 0 || sum > 100000000) { ViewBag.Result = Message.SumIntervalMismatch; return View(); } if (sum > client.State.BankMoney) { ViewBag.Result = Message.NotEnoughBankMoney; return View(); } MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.TransferMoneyFromBankIdToBankId(sum, clientTo); Operation operation = new Operation(DateTime.Now, client.Id, "Transfer", client.State.BankId, String.Empty, clientTo.State.BankId, String.Empty, sum); _clientsRepository.SaveObject(client); LogInInfo.UpdateLoggedInClient(); _clientsRepository.SaveObject(clientTo); _operationsRepository.SaveObject(operation); ViewBag.Result = Message.OperationSuccessed; return View(); }
public ActionResult TakeCreditConfirmed(FormCollection form) { Client client = LogInInfo.LoggedInClient(); Credit credit = (Credit)Session["credit"]; if (credit == null) { return RedirectToAction("TakeCredit"); } int creditSum = int.Parse(form["Sum"]); if (client.State.BankId != form["BankId"]) { ViewBag.Result = Message.WrongId; return View(credit); } credit.Money = creditSum; credit.ClientId = client.Id; MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.TakeCredit(credit); _creditsRepository.SaveObject(credit); Operation operation = new Operation(DateTime.Now, client.Id, string.Format("Take for {0}", credit.Type), String.Empty, String.Empty, client.State.BankId, String.Empty, creditSum); _operationsRepository.SaveObject(operation); _clientsRepository.SaveObject(client); LogInInfo.UpdateLoggedInClient(); ViewBag.Result = Message.OperationSuccessed; return View(credit); }
public ActionResult PutMoney(FormCollection form) { Client client = LogInInfo.LoggedInClient(); string bankId = form["BankId"]; int sum; try { sum = int.Parse(form["Sum"]); } catch (FormatException) { ViewBag.Result = Message.WrongSum; return View(); } if (client == null) { return RedirectToAction("Login", "Account"); } if (client.State.BankId != bankId) { ViewBag.Result = Message.WrongId; return View(); } if (sum <= 0 || sum > 100000000) { ViewBag.Result = Message.WrongSum; return View(); } MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.PutMoney(sum); Operation operation = new Operation(DateTime.Now, client.Id, "Put", client.State.BankId, String.Empty, String.Empty, String.Empty, sum); _clientsRepository.SaveObject(client); LogInInfo.UpdateLoggedInClient(); _operationsRepository.SaveObject(operation); ViewBag.Result = Message.OperationSuccessed; return View(); }
public ActionResult PayCredit(FormCollection form) { Client client = LogInInfo.LoggedInClient(); Credit credit = (Credit)Session["credit"]; if (credit == null) { return RedirectToAction("PayCredit"); } string bankId = form["BankId"]; int creditSum = int.Parse(form["Sum"]); if (client == null) { return RedirectToAction("Login", "Account"); } if (client.State.BankId != bankId) { ViewBag.Result = Message.WrongId; return View(credit); } if (creditSum <= 0 || creditSum > 100000000) { ViewBag.Result = Message.SumIntervalMismatch; return View(credit); } if (creditSum > client.State.BankMoney) { ViewBag.Result = Message.NotEnoughBankMoney; return View(credit); } if (creditSum > credit.Money) { ViewBag.Result = Message.WrongSumForCredit; return View(credit); } MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.PayCredit(creditSum, credit); _creditsRepository.SaveObject(credit); Operation operation = new Operation(DateTime.Now, client.Id, string.Format("Pay for {0}", credit.Type), client.State.BankId, String.Empty, String.Empty, String.Empty, creditSum); _operationsRepository.SaveObject(operation); _clientsRepository.SaveObject(client); LogInInfo.UpdateLoggedInClient(); ViewBag.Result = Message.OperationSuccessed; return View(credit); }
public ActionResult Update(FormCollection form) { string button = form["Update"]; int id = int.Parse(form["Id"]); Client client = _clientsRepository.Objects.SingleOrDefault(c => c.Id == id); if (client == null) { return View(); } if (button == "CreditsMoney") { List<Credit> credits = client.GetObjects(_creditsRepository); if (client.AccountType == "Usual" || credits.Count == 0) { ErrorNotifier notifier = new ErrorNotifier { Source = "updateCredits" }; notifier.SetDescription(); return RedirectToAction("Error", "Admin", notifier); } MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.UpdateClientCredits(credits); foreach (Credit credit in credits) { Operation operation = new Operation(DateTime.Now, client.Id, string.Format("Update credit for {0}", credit.Type), String.Empty, String.Empty, client.State.BankId, String.Empty, credit.Money*credit.Procents/100); _operationsRepository.SaveObject(operation); } _clientsRepository.SaveObject(client); } if (button == "BankMoney") { if (client.State.BankMoney == 0) { ErrorNotifier notifier = new ErrorNotifier { Source = "updateBank" }; notifier.SetDescription(); return RedirectToAction("Error", "Admin", notifier); } int procents = client.State.BankMoney * client.State.BankProcents / 100; MoneyOperations moneyOperation = new MoneyOperations(client); moneyOperation.UpdateClientBankMoney(); Operation operation = new Operation(DateTime.Now, client.Id, string.Format("Update bank money"), String.Empty, String.Empty, client.State.BankId, String.Empty, procents); _operationsRepository.SaveObject(operation); _clientsRepository.SaveObject(client); } return RedirectToAction("OperationsLog", "Admin"); }