Beispiel #1
0
        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 == "*****@*****.**"))
            {
                //23/2
                //create a new user
                var adminUser = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                userManager.Create(adminUser, password: "******");

                // the new user to checking account
                var service = new CheckingAccountService(context);
                service.CreateCheckingAccount("admin", "user", adminUser.Id, 1000);

                //adding a role to the database
                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole {
                    Name = "Admin"
                });
                context.SaveChanges();

                //adding a the role to the admin user
                userManager.AddToRole(userId: adminUser.Id, role: "Admin");
            }

            //  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.
        }
Beispiel #2
0
        public void IsBalanceCorrectAfterWithdrawal()
        {
            var fakeDb = new FakeApplicationDbContext();

            fakeDb.CheckingAccounts = new FakeDbSet <CheckingAccount>();
            var checkingAccount = new CheckingAccount {
                Id = 1, AccountNumber = "000123TEST", Balance = 100
            };

            fakeDb.CheckingAccounts.Add(checkingAccount);
            fakeDb.Transactions = new FakeDbSet <Transaction>();

            var service     = new CheckingAccountService(fakeDb);
            var transaction = new Transaction {
                CheckingAccountId = 1, Amount = 20
            };

            transaction.Amount = -transaction.Amount;
            fakeDb.Transactions.Add(new Transaction {
                Amount = 100, CheckingAccountId = 1
            });
            fakeDb.Transactions.Add(transaction);
            fakeDb.SaveChanges();

            service.UpdateBalance(transaction.CheckingAccountId);

            Assert.AreEqual(80, checkingAccount.Balance);
        }
        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 db      = new ApplicationDbContext();
                    var service = new CheckingAccountService(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 https://go.microsoft.com/fwlink/?LinkID=320771
                    // E-Mail-Nachricht mit diesem Link senden
                    // 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, "Konto bestätigen", "Bitte bestätigen Sie Ihr Konto. Klicken Sie dazu <a href=\"" + callbackUrl + "\">hier</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // Wurde dieser Punkt erreicht, ist ein Fehler aufgetreten; Formular erneut anzeigen.
            return(View(model));
        }
        /// <summary>
        /// Contructor
        /// </summary>
        public CheckingAccountServiceTest()
        {
            var checkingAccountRepository = new Mock <ICheckingAccountRepository>();

            checkingAccountRepository.Setup(x => x.SelectByNumber("111")).Returns((string i) =>
            {
                return(new CheckingAccount()
                {
                    Id = 1,
                    Number = "111"
                });
            });

            var postRepository = new Mock <IPostRepository>();

            postRepository.Setup(x => x.Select(1)).Returns((int i) =>
            {
                return(new Post()
                {
                    Id = 1,
                    IDOriginAccount = 1,
                    IDDestinationAccount = 2,
                    Value = 200,
                });
            });

            _checkingAccountService = new CheckingAccountService(checkingAccountRepository.Object, postRepository.Object);
        }
        public ActionResult Transfare(TransfareViewModel transfareViewModel)
        {
            var sender = new Transaction {
                Amount = transfareViewModel.Amount * -1, CheckingAccountId = transfareViewModel.CheckingAccountId
            };
            var receiverId = db.CheckingAccounts.Where(r => r.AccountNumber == transfareViewModel.AccountNumber).First().Id;

            var receiver = new Transaction {
                CheckingAccountId = receiverId, Amount = transfareViewModel.Amount
            };

            if (ModelState.IsValid)
            {
                db.Transactions.Add(sender);
                db.SaveChanges();
                db.Transactions.Add(receiver);
                db.SaveChanges();

                var service = new CheckingAccountService(db);
                service.UpdateBalance(sender.CheckingAccountId);
                var service2 = new CheckingAccountService(db);
                service2.UpdateBalance(receiver.CheckingAccountId);



                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Beispiel #6
0
        public ActionResult TransferFunds(string transferToId, Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                var service = new CheckingAccountService(db);
                try
                {
                    transaction.Amount = transaction.Amount * (-1);
                    db.Transactions.Add(transaction);
                    service.UpdateBalance(transaction.CheckingAccountId);
                    transaction.Amount            = transaction.Amount * (-1);
                    transaction.CheckingAccountId = int.Parse(transferToId);
                    db.Transactions.Add(transaction);
                    service.UpdateBalance(transaction.CheckingAccountId);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Beispiel #7
0
        public ActionResult Transfer(TransferViewModel transfer)
        {
            var sourceCheckingAccount = db.CheckingAccountModels.Find(transfer.CheckingAccountId);

            if (sourceCheckingAccount.Balance < transfer.Amount)
            {
                ModelState.AddModelError("Amount", "You have insufficient funds");
            }
            var destinationCheckingAccount =
                db.CheckingAccountModels.Where(c => c.AccountNumber == transfer.DestinationCheckingAccountNumber).FirstOrDefault();

            if (destinationCheckingAccount == null)
            {
                ModelState.AddModelError("DestinationCheckingAccountNumber", "Invalid destination account number");
            }
            if (ModelState.IsValid)
            {
                db.Transactions.Add(new Transaction {
                    CheckingAccountId = transfer.CheckingAccountId, Amount = -transfer.Amount
                });
                db.Transactions.Add(new Transaction {
                    CheckingAccountId = destinationCheckingAccount.Id, Amount = transfer.Amount
                });
                db.SaveChanges();

                var service = new CheckingAccountService(db);
                service.UpdateBalance(transfer.CheckingAccountId);
                service.UpdateBalance(destinationCheckingAccount.Id);
                return(PartialView("_TransferSuccess", transfer));
            }
            return(PartialView("_TransferForm"));
        }
        protected override void Seed(MVCATM.Models.ApplicationDbContext context)
        {
            //  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.
            var userStore       = new UserStore <ApplicationUser>(context);
            var userManager     = new UserManager <ApplicationUser>(userStore);
            var checkingAccount = new CheckingAccount();

            if (!context.Users.Any(t => t.UserName == "*****@*****.**"))
            {
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", Pin = "8975"
                };
                userManager.Create(user, "passW0rd!");

                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole {
                    Name = "Admin"
                });
                context.SaveChanges();

                userManager.AddToRole(user.Id, "Admin");

                Repository repository = new Repository(context);

                var service = new CheckingAccountService(repository);
                service.CreateCheckingAccount("admin", "user", user.Id, 0);

                checkingAccount = repository.GetAccountByUserId(user.Id);

                Transaction transactionInitial = new Transaction {
                    Amount = 1000, checkingAccount = checkingAccount, CheckingAccountId = checkingAccount.Id
                };
                service.MakeTransaction(transactionInitial);



                //checkingAccount = repository.GetAccountByUserId(user.Id);

                //var transaction = new Transaction { Amount = 100, CheckingAccountId = checkingAccount.Id };
                //List<Transaction> transactions = new List<Transaction> { transaction};
                //for(int i=0;i<20;i++)
                //{
                //    if(i%2 == 0)
                //    {
                //        transaction = new Transaction { Amount = 200, CheckingAccountId = checkingAccount.Id };
                //    }
                //    else
                //    {
                //        transaction = new Transaction { Amount = -50, CheckingAccountId = checkingAccount.Id };
                //    }
                //    transactions.Add(transaction);
                //}
                //foreach(Transaction trans in transactions)
                //{
                //    service.MakeTransaction(trans);
                //}
            }
        }
        protected override void Seed(ATMMvc.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, "pAssw0rd!");
                var service = new CheckingAccountService(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 = -300, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = 300, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = -1300.45m, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = 2500, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = -3500, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = 75000, CheckingAccountId = 1 });
            //context.Transactions.Add(new Transaction { Amount = 9800.50m, CheckingAccountId = 1 });
            //  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.
        }
Beispiel #10
0
        protected override void Seed(ATM.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, "Brandy_1814");

                var service = new CheckingAccountService(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");
            }
            //  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" }
            //    );
            //
        }
        protected override void Seed(ApplicationDbContext context)
        {
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            if (!context.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                userManager.Create(user, "passW0rd!");

                var service = new CheckingAccountService(context);
                service.CreateCheckingAccount("Admin", "Pesho", user.Id, 1500m);

                var role = new IdentityRole {
                    Name = "Admin"
                };

                context.Roles.AddOrUpdate(x => x.Name, role);
                context.SaveChanges();

                userManager.AddToRole(user.Id, "Admin");
            }
        }
Beispiel #12
0
        protected override void Seed(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, "Martin123.");

                var service = new CheckingAccountService(context);
                service.CreateCheckingAccount("Vuyani", "Shabangu", user.Id, 50000);

                var admin = new IdentityRole {
                    Name = "Admin"
                };
                context.Roles.AddOrUpdate(r => r.Name, admin);
                context.SaveChanges();

                userManager.AddToRole(user.Id, "Admin");
            }
            //  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.
        }
        public CheckingAccountServiceTest()
        {
            checkingAccountMock           = Substitute.For <CheckingAccount>();
            checkingAccountRepositoryMock = Substitute.For <ICheckingAccountRepository>();

            checkingAccountService = new CheckingAccountService(checkingAccountRepository);
        }
        protected override void Seed(AutomatedTellerMachine.Models.IApplicationDbContext 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, "passW0rd!");
                var service = new CheckingAccountService(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 = 75, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = -25, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 100000, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 19.99m, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 64.40m, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 100, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = -300, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 255.75m, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 198, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 2, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 50, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = -1.50m, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 6100, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = 164.84m, CheckingAccountId = 9 });
            context.Transactions.Add(new Transaction { Amount = .01m, CheckingAccountId = 9 });

        }
Beispiel #15
0
        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 CheckingAccountService(HttpContext.GetOwinContext
                                                                 ().Get <IApplicationDbContext>());
                    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 https://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));
        }
Beispiel #16
0
        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)
                {
                    //Adding a claim & add to details to db details for user.

                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));//adding claims(by GivenNames)
                    var service = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                    service.CreateCheckingAccount(model.FirstName, model.LastName, user.Id, 0);
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #17
0
        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, "passW0rd!");

                var service = new CheckingAccountService(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");
            }
            //  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.
        }
Beispiel #18
0
        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 CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());

                    service.CreateCheckingAccount(model.FirstName, model.LastName, user.Id, 0.00m);

                    //var db = new ApplicationDbContext();
                    //var totalAccounts = db.CheckingAccounts.Count();
                    //var checkingAccount = new CheckingAccount
                    //{
                    //    FirstName = model.FirstName,
                    //    LastName = model.LastName,
                    //    AccountNumber = String.Format($"{totalAccounts}").PadLeft(10, '0'),
                    //    Balance = 0.00m,
                    //    ApplicationUserId = user.Id
                    //};

                    //db.CheckingAccounts.Add(checkingAccount);
                    //db.SaveChanges();

                    //try
                    //{
                    //    db.CheckingAccounts.Add(checkingAccount);
                    //    db.SaveChanges();
                    //}
                    //catch (DbEntityValidationException e)
                    //{
                    //    var newException = new FormattedDbEntityValidationException(e);
                    //    throw newException;
                    //}

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://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));
        }
Beispiel #19
0
        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    = "*****@*****.**"
                };
                IdentityResult result = userManager.Create(user, "Password1!");

                var service = new CheckingAccountService(context);
                service.CreateCheckingAccount("admin", "user", user.Id, 1000);

                context.Roles.AddOrUpdate(t => t.Name, new IdentityRole {
                    Name = "Admin"
                });
                context.SaveChanges();

                userManager.AddToRole(user.Id, "Admin");
                context.SaveChanges();
            }

            //context.Transactions.Add(new Transaction { Amount = 75, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -25, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 100000, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 19.99m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 64.40m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 100, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -300, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 255.75m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 198, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 2, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 50, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -1.50m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 6100, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 164.84m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = .01m, 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" }
            //    );
            //
        }
Beispiel #20
0
        //Mycode
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //======Review 18/2
                    //var db = new ApplicationDbContext();
                    //var accountNumber = (123456 + db.CheckingAccounts.Count()).ToString().PadLeft(10,'0');
                    //var checkingAccount = new CheckingAccount {
                    //    FirstName = model.FirstName, LastName = model.LastName,AccountNumber= accountNumber,
                    //    Balance=0
                    //,ApplicationUserId= user.Id};
                    //
                    //db.CheckingAccounts.Add(checkingAccount);
                    //db.SaveChanges();
                    //========end review 18/2

                    //21/2 coding the service
                    var service = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                    service.CreateCheckingAccount(
                        firstName: model.FirstName,
                        lastName: model.LastName,
                        userId: user.Id,
                        initialBalance: 0
                        );
                    //21/2

                    //add a Claim to use easly
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));


                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://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 Deposit(Transaction transaction)
 {
     if (ModelState.IsValid)
     {
         db.Transactions.Add(transaction);
         db.SaveChanges();
         var service = new CheckingAccountService(db);
         service.UpdateBalance(transaction.CheckingAccountId);
         return(RedirectToAction("Index", "Home"));
     }
     return(View());
 }
        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)
                {
                    //working on cliams in cookies added to _loginPartial.cshtml
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));
                    //var db = new ApplicationDbContext();
                    //var accountNumber = (123456 + db.CheckingAccounts.Count()).ToString().PadLeft(10, '0');
                    //var checkingAcoount = new CheckingAccount
                    //{
                    //    FirstName = model.FirstName,
                    //    LastName = model.LastName,
                    //    AccountNumber = accountNumber,
                    //    Balance = 0,
                    //    ApplicationUserId = user.Id
                    //};
                    //db.CheckingAccounts.Add(checkingAcoount);
                    //db.SaveChanges();

                    // code moved to checking CheckinAccountService.cs

                    //replacing the code with a new instance of checking accpount service
                    var service = new CheckingAccountService(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 https://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));
        }
Beispiel #23
0
 public ActionResult Deposit(Transaction transaction)
 {
     if (ModelState.IsValid)
     {
         db.Transactions.Add(transaction);
         db.SaveChanges();
         var service = new CheckingAccountService(db);
         service.UpdateBalance(transaction.CheckingAccountId);
         string body    = String.Format("Dear Customer,\nYour deposit (${0}) has been successfully created.\nBest regards - Bank of Sunnyvale", transaction.Amount);
         string subject = "Deposit - Bank of Sunnyvale";
         SendMailToUser(subject, body);
         return(PartialView("_DepositSuccess"));
     }
     return(View());
 }
Beispiel #24
0
        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)
                    {
                        //21/2 coding the service
                        var service = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                        service.CreateCheckingAccount(
                            firstName: "Facebook",
                            lastName: "User",
                            userId: user.Id,
                            initialBalance: 500
                            );
                        //21/2

                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        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, "Abcd1234!");
                var service = new CheckingAccountService(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 = 75, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 25, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 3213.89m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 32.54m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -45, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -377, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 24.78m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 145, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 278, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -255, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -1.57m, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = 2478, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -600, CheckingAccountId = 5 });
            //context.Transactions.Add(new Transaction { Amount = -.07m, 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" }
            //    );
            //
        }
Beispiel #26
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("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
                };
                IdentityResult result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        var service = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                        service.CreatingCheckingAccount("Faceboo", "User", user.Id, 500);
                        await SignInAsync(user, isPersistent : 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);
                        // SendEmail(user.Email, callbackUrl, "Confirm your account", "Please confirm your account by clicking this link");

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Beispiel #27
0
        public ActionResult Deposit(Transaction transaction)
        {
            var userId          = User.Identity.GetUserId();
            var checkingAccount = db.CheckingAccounts.Where(c => c.ApplicationUserId == userId).First();

            if (ModelState.IsValid)
            {
                transaction.TransactionDate = DateTime.Now;
                transaction.Source          = checkingAccount.Name;
                db.Transactions.Add(transaction);
                db.SaveChanges();

                var service = new CheckingAccountService(db);
                service.UpdateBalance(transaction.CheckingAccountId);
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Beispiel #28
0
 public ActionResult QuickCash(Transaction transaction)
 {
     transaction.Amount = -100.00m;
     if (db.CheckingAccounts.Find(transaction.CheckingAccountId).Balance < Math.Abs(transaction.Amount))
     {
         //do they have enough money?
         ModelState.AddModelError("", "You've insufficient funds!");
     }
     if (ModelState.IsValid)
     {
         db.Transactions.Add(transaction);
         db.SaveChanges();
         var service = new CheckingAccountService(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"));
                }

                //creats system user after external login successed
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    //insert a row in the AspNetUserLogins table, associating the Facebook user ID with our system's user
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        var service = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                        service.CreateCheckingAccount("facebook", "User", user.Id, 500); //running a promotion that gives Facebook users 500 dollars for signing up with us

                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Beispiel #30
0
        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 = info.DefaultUserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    CheckingAccountService checkingAccountService = new CheckingAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                    checkingAccountService.CreateCheckingAccount(info.ExternalIdentity.Name, "user", user.Id, 500);

                    //UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, info.ExternalIdentity.NameClaimType));

                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }