public IActionResult CreateNewBonus(NewBonusSavingsAccountViewModel vm) { if (!vm.CustomerList.Any(pc => pc.IsSelected)) { vm.DisplayMessage = "Must select at least one account owner"; return(View(vm)); } else if (vm.InitialBalance < 0) { vm.DisplayMessage = "Please input a positive sum for initial balance"; return(View(vm)); } else { //get bank data, then save account to file and send back to start page var bank = Utility.Utility.GetBankData(_env.WebRootPath); var selectedOwners = vm.CustomerList.Where(pc => pc.IsSelected); var owners = new List <PrivateCustomer>(); foreach (var owner in selectedOwners) { owners.Add(bank.PrivateCustomers.Single(pc => pc.CustomerID == owner.CustomerID)); } var account = new BonusSavingsAccount(owners, vm.InitialBalance); bank.BonusSavingsAccounts.Add(account); //now save to file Utility.Utility.SaveBankData(_env.WebRootPath, bank); return(RedirectToAction("Index", "Home", new { message = Message.CreatePrivateAccountSuccess })); } }
public IActionResult CreateNewBonus() { NewBonusSavingsAccountViewModel vm = new NewBonusSavingsAccountViewModel(); vm.CustomerList = Utility.Utility.GetBankData(_env.WebRootPath).PrivateCustomers; return(View(vm)); }