public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName)); var service = new CheckingAccountServices(HttpContext.GetOwinContext().Get <ApplicationDbContext>()); service.CreateCheckingAccount(model.FirstName, model.LastName, user.Id, 0); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Transfer(TransferViewModel Transfer) { var sourceCheckingAccount = db.ChekingAccounts.Find(Transfer.CheckingAccountId); if (sourceCheckingAccount.Balance < Transfer.Amount) { ModelState.AddModelError("Amount", "You have insufficient funds"); } var destCheckingAccount = db.ChekingAccounts.Where(c => c.AccountNumber == Transfer.DestinationAccountNumber).FirstOrDefault(); if (destCheckingAccount == null) { ModelState.AddModelError("DestinationAccountNumber", "Invalid Destination Checking Account Number"); } if (ModelState.IsValid) { db.Transactions.Add(new Transaction { CheckingAccountId = Transfer.CheckingAccountId, Amount = -Transfer.Amount }); db.Transactions.Add(new Transaction { CheckingAccountId = destCheckingAccount.Id, Amount = Transfer.Amount }); db.SaveChanges(); var service = new CheckingAccountServices(db); service.UpdateBalance(Transfer.CheckingAccountId); service.UpdateBalance(destCheckingAccount.Id); return(PartialView("_TransferSuccess", Transfer)); } return(PartialView("_TransferForm")); }
protected override void Seed(AutomatedTellerMachine.Models.ApplicationDbContext context) { var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); if (!context.Users.Any(t => t.UserName == "*****@*****.**")) { var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; userManager.Create(user, "Pass!23"); var service = new CheckingAccountServices(context); service.CreateCheckingAccount("admin", "user", user.Id, 1000); context.Roles.AddOrUpdate(r => r.Name, new IdentityRole { Name = "Admin" }); context.SaveChanges(); userManager.AddToRole(user.Id, "Admin"); } //context.Transactions.Add(new Transaction { Amount = -1.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 4.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 5.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 61.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -1.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 21.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -21.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -41.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 56.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 767.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 23.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 1.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 431.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -3.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -143.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -11.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -5.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -2.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = -31.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 221.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 41.50m, CheckingAccountId = 5 }); //context.Transactions.Add(new Transaction { Amount = 77.50m, CheckingAccountId = 5 }); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
public ActionResult Deposit(Transaction transaction) { if (ModelState.IsValid) { db.Transactions.Add(transaction); db.SaveChanges(); var service = new CheckingAccountServices(db); service.UpdateBalance(transaction.CheckingAccountId); return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult TransferFunds(TransferFundsViewModel transferFunds) { //Check for available funds CheckingAccount sourceAccount = db.CheckingAccounts.Find(transferFunds.SourceAccountId); if (sourceAccount.Balance < transferFunds.Amount) { ModelState.AddModelError("Amount", "Insufficient funds in source account"); } //Check if destination account exists CheckingAccount destAccount = db.CheckingAccounts.Where( c => c.Id == transferFunds.DestinationAccountId).FirstOrDefault(); if (destAccount == null) { ModelState.AddModelError("DestinationAccountId", "Destination account does not exist"); } if (ModelState.IsValid) { //Add source account transaction Transaction srcTransaction = new Transaction(); srcTransaction.Account = sourceAccount; srcTransaction.CheckingAccountId = sourceAccount.Id; srcTransaction.Amount = -transferFunds.Amount; //amount to deduct db.Transactions.Add(srcTransaction); //Add destination account transaction Transaction destTransaction = new Transaction(); destTransaction.Account = destAccount; destTransaction.CheckingAccountId = destAccount.Id; destTransaction.Amount = transferFunds.Amount; db.Transactions.Add(destTransaction); //Save to db and update balance for both accounts db.SaveChanges(); var service = new CheckingAccountServices(db); service.UpdateBalance(srcTransaction); service.UpdateBalance(destTransaction); return(PartialView("_TransferSuccess", transferFunds)); } return(PartialView("_TransferForm", transferFunds)); }
public ActionResult Withdrawal(Transaction Transaction) { var checkingaccount = db.ChekingAccounts.Find(Transaction.CheckingAccountId); if (checkingaccount.Balance < Transaction.Amount) { ModelState.AddModelError("Amount", "You have insufficient funds"); } if (ModelState.IsValid) { Transaction.Amount = -Transaction.Amount; db.Transactions.Add(Transaction); db.SaveChanges(); var service = new CheckingAccountServices(db); service.UpdateBalance(Transaction.CheckingAccountId); return(RedirectToAction("Index", "Home")); } return(View()); }
public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { var service = new CheckingAccountServices(HttpContext.GetOwinContext().Get <ApplicationDbContext>()); service.CreateCheckingAccount("Facebook", "User", user.Id, 500); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToLocal(returnUrl)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }