public ActionResult Account(AccountViewModel vm) { using (var unitOfWork = new UnitOfWork.UnitOfWorkScope <BankingDbContext>(UnitOfWork.UnitOfWorkScopePurpose.Writing)) { AuthenticationService authenticate = new AuthenticationService(); var userEmail = (string)HttpContext.Session["User"]; var user = authenticate.GetUser(userEmail); vm.UserName = user.Name; var account = _efrAccount.GetDbSet().Where(x => x.User.Id == user.Id).Include(m => m.TransactionList).ToList(); bool flag = false; foreach (var acc in account) { if (acc.AccountType.Equals(AccountType.SAVING.ToString())) { flag = true; vm.Message = "Saving Account Exist for User" + user.Name + " Amount " + acc.Balance; } } if (flag == false) { Account savingAccount = new Account(AccountType.SAVING.ToString(), 5000) { User = user }; _efrAccount.Add(savingAccount); vm.Message = "Account Successfully Created"; } unitOfWork.SaveChanges(); } return(View(vm)); }
public ActionResult AddRecipient(AddRecipientViewModel vm) { using ( var unitOfWork = new UnitOfWork.UnitOfWorkScope <BankingDbContext>(UnitOfWork.UnitOfWorkScopePurpose.Writing)) { AuthenticationService authenticate = new AuthenticationService(); var userEmail = (string)HttpContext.Session["User"]; var user = authenticate.GetUser(userEmail); vm.UserName = user.Name; if (ModelState.IsValid) { try { var users = _efrUser.GetDbSet() .Where(m => m.Id == user.Id) .Include(m => m.RecipientList) .First(); Recipient recipient = new Recipient(vm.Name, vm.Amount); users.RecipientList.Add(recipient); vm.Message = "Recipient Successfully Added"; unitOfWork.SaveChanges(); return(RedirectToAction("Recipient", "User")); } catch (Exception) { } } } return(View(vm)); }
public ActionResult Recipient(RecipientViewModel vm) { using (var unitOfWork = new UnitOfWork.UnitOfWorkScope <BankingDbContext>(UnitOfWork.UnitOfWorkScopePurpose.Writing)) { AuthenticationService authenticate = new AuthenticationService(); var userEmail = (string)HttpContext.Session["User"]; var user = authenticate.GetUser(userEmail); vm.UserName = user.Name; if (ModelState.IsValid && vm.Name != null) { vm.SelectedList = PopulateList(); try { var account = _efrAccount.GetDbSet() .Where(x => x.User.Id == user.Id) .Where(x => x.AccountType == vm.AccountType) .Include(m => m.TransactionList) .First(); var recipient = _efrRecipient.GetDbSet() .Where(x => x.User.Id == user.Id) .Where(x => x.Name == vm.Name) .First(); recipient.Balance += vm.Amount; account.TransactionList.Add(new Transaction(vm.Amount, TransactionType.WITHDRAW.ToString(), DateTime.Now)); vm.Message = "Transaction successful with Recipient"; } catch (Exception) { // ignored } unitOfWork.SaveChanges(); } } return(View(vm)); }