public override string Execute() { // ListAccounts if (!this.AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(OutputMessages.UserShouldLogIn); } var builder = new StringBuilder(); using (var context = new BankSystemDbContext()) { var user = this.AuthenticationManager.GetCurrentUser(); context.Users.Attach(user); builder.AppendLine("Saving Accounts:"); foreach (var account in user.SavingsAccounts) { builder.AppendLine(string.Format(OutputMessages.AccountBalance, account.AccountNumber, account.Balance)); } builder.AppendLine("Checking Accounts:"); foreach (var account in user.CheckingAccounts) { builder.AppendLine(string.Format(OutputMessages.AccountBalance, account.AccountNumber, account.Balance)); } } return(builder.ToString().Trim()); }
public override string Execute() { // Login <username> <password> if (this.CommandArgs.Length != 2) { throw new ArgumentException(OutputMessages.InvalidInput); } if (this.AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(OutputMessages.UserShouldLogOut); } var username = this.CommandArgs[0]; var password = this.CommandArgs[1]; using (var context = new BankSystemDbContext()) { var user = context.Users .FirstOrDefault(u => u.Username == username && u.Password == password); if (user == null) { throw new ArgumentException(OutputMessages.InvalidUsernameOrPassword); } this.AuthenticationManager.Login(user); } return(string.Format(OutputMessages.UserLoggedIn, username)); }
private static void RegisterUser(BankSystemDbContext db, string[] parts) { var username = parts[1]; var password = parts[2]; var email = parts[3]; try { var user = new User { Username = username, Password = password, Email = email }; db .Users .Add(user); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public override string Execute() { // withdraw <Account number> <money> if (this.CommandArgs.Length != 2) { throw new ArgumentException(OutputMessages.InvalidInput); } if (!this.AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(OutputMessages.UserShouldLogIn); } var accountNumber = this.CommandArgs[0]; var amount = decimal.Parse(this.CommandArgs[1]); if (amount <= 0) { throw new ArgumentException(OutputMessages.AmountShouldBePositive); } decimal currentBalance; using (var context = new BankSystemDbContext()) { var user = this.AuthenticationManager.GetCurrentUser(); context.Users.Attach(user); var savingsAccount = user .SavingsAccounts .FirstOrDefault(a => a.AccountNumber == accountNumber); var checkingAccount = user .CheckingAccounts .FirstOrDefault(a => a.AccountNumber == accountNumber); if (savingsAccount == null && checkingAccount == null) { throw new ArgumentException(OutputMessages.InvalidAccount); } if (savingsAccount != null) { savingsAccount.WithdrawMoney(amount); context.SaveChanges(); currentBalance = savingsAccount.Balance; } else { checkingAccount.WithdrawMoney(amount); context.SaveChanges(); currentBalance = checkingAccount.Balance; } } return(string.Format(OutputMessages.AccountHasBalance, accountNumber, currentBalance)); }
public static void Main() { using (var db = new BankSystemDbContext()) { while (true) { var command = Console.ReadLine(); if (command == "exit") { break; } var parts = command .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var action = parts[0]; if (action == "Register") { RegisterUser(db, parts); } if (action == "Login") { LoginUser(db, parts); } } } }
private static async Task SeedUser(UserManager <BankUser> userManager, BankSystemDbContext dbContext) { if (!dbContext.Users.Any()) { var user = new BankUser { Email = "*****@*****.**", FullName = "Test Testov", UserName = "******", EmailConfirmed = true, BankAccounts = new List <BankAccount> { new BankAccount { Balance = 10000, CreatedOn = DateTime.UtcNow, Name = "Main account", UniqueId = "ABCJ98131785" } } }; await userManager.CreateAsync(user, "Test123$"); } }
public void Run() { using (var db = new BankSystemDbContext()) { InitializeDatabase(db); var input = Console.ReadLine(); while (input != "End") { var inputArgs = input.Split().ToList(); var command = inputArgs[0]; inputArgs.RemoveAt(0); switch (command) { case "Register": RegisterUser(db, inputArgs); break; } input = Console.ReadLine(); } } }
public Engine(BankSystemDbContext context, ICommandParser commandParser, IUserSession userSession, IReader reader, IWriter writer) { this.context = context; this.reader = reader; this.writer = writer; this.commandParser = commandParser; this.userSession = userSession; }
private void InitializeDatabase(BankSystemDbContext db) { Console.WriteLine("Initializing database..."); db.Database.EnsureDeleted(); db.Database.EnsureCreated(); Console.WriteLine("Database Ready."); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); BankSystemDbContext context = new BankSystemDbContext(); context.Database.CreateIfNotExists(); }
public static void Main() { using (BankSystemDbContext database = new BankSystemDbContext()) { //PrepareDatabase(database); IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); ICommandInterpreter commandDispatcher = new CommandInterpreter(database); IEngine engine = new Engine(commandDispatcher, reader, writer); engine.Run(); } }
public void InitializeDatabase() { using (var context = new BankSystemDbContext()) { this.writer.WriteMessage("Initializing database..."); context.Database.EnsureDeleted(); //context.Database.EnsureCreated(); context.Database.Migrate(); this.writer.WriteMessage("Database ready!"); } }
private static void LoginUser(BankSystemDbContext db, string[] parts) { var username = parts[1]; var password = parts[2]; if (db.Users.Any(u => u.Username == username && u.Password == password)) { Console.WriteLine($"{username} successfully logged in"); } else { Console.WriteLine($"Incorrect username/password"); } }
public static void Main(string[] args) { BankSystemDbContext context = new BankSystemDbContext(); InitialteDatabase(context); IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); ICommandParser commandParser = new CommandParser(context); IUserSession userSession = new UserSession(); var engine = new Engine(context, commandParser, userSession, reader, writer); engine.Run(); }
public async Task <ActionResult> Register(RegisterUserView userView) { if (ModelState.IsValid) { //Upload Image: string path = string.Empty; string picture = string.Empty; if (userView.Photo != null) { picture = Path.GetFileName(userView.Photo.FileName); path = Path.Combine(Server.MapPath("~/Content/Photos"), picture); userView.Photo.SaveAs(path); using (MemoryStream ms = new MemoryStream()) { userView.Photo.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } } var userASP = createASPUser(userView); //Save record: var user = new User { Id = userASP.Id, Address = userView.Address, FirstName = userView.FirstName, MiddleName = userView.MiddleName, LastName = userView.LastName, Username = userView.userName }; var context = new BankSystemDbContext(); context.Users.Add(user); context.SaveChanges(); await SignInManager.SignInAsync(userASP, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Home")); } // If we got this far, something failed, redisplay form return(View(userView)); }
public override string Execute() { // Register <username> <password> <email> if (this.CommandArgs.Length != 3) { throw new ArgumentException(OutputMessages.InvalidInput); } if (this.AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(OutputMessages.UserShouldLogOut); } var username = this.CommandArgs[0]; var password = this.CommandArgs[1]; var email = this.CommandArgs[2]; var user = new User() { Username = username, Password = password, Email = email }; this.ValidateUser(user); using (var context = new BankSystemDbContext()) { if (context.Users.Any(u => u.Username == username)) { throw new ArgumentException(OutputMessages.UsernameTaken); } if (context.Users.Any(u => u.Email == email)) { throw new ArgumentException(OutputMessages.EmailTaken); } context.Users.Add(user); context.SaveChanges(); } return(string.Format(OutputMessages.UserRegistered, username)); }
private void RegisterUser(BankSystemDbContext db, List <string> inputArgs) { var username = inputArgs[0]; var password = inputArgs[1]; var email = inputArgs[2]; var user = new User { Username = username, Password = password, Email = email }; db.Users.Add(user); db.SaveChanges(); Console.WriteLine($"User {username} is registered in the database."); }
private static async Task SeedUser(UserManager <BankUser> userManager, BankSystemDbContext dbContext) { if (!dbContext.Users.Any()) { var user = new BankUser { Email = "*****@*****.**", FullName = "Nagy Zoltán", UserName = "******", EmailConfirmed = true, BankAccounts = new List <BankAccount> { new BankAccount { Balance = 1000000, Credit = 50000, InterestRate = 10, Currency = BankAccount.CurrencyType.HUF, CreatedOn = DateTime.UtcNow, Name = "Main account", UniqueId = "ABCL73206545", TypeId = BankAccount.AccountType.NormalAccount }, new BankAccount { Balance = 5000, // one time bonus Credit = 0, InterestRate = 0, Currency = BankAccount.CurrencyType.HUF, CreatedOn = DateTime.UtcNow, Name = "Savings account", UniqueId = "ABCU18458713", TypeId = BankAccount.AccountType.SavingAccount } } }; await userManager.CreateAsync(user, "Admin1!"); } }
private void AddSavingsAccount(string accountNumber, decimal balance, decimal rateOrFee) { var savingsAccount = new SavingsAccount() { AccountNumber = accountNumber, Balance = balance, InterestRate = rateOrFee }; this.ValidateSavingsAccount(savingsAccount); using (var context = new BankSystemDbContext()) { var user = this.AuthenticationManager.GetCurrentUser(); context.Users.Attach(user); savingsAccount.User = user; context.SavingsAccounts.Add(savingsAccount); context.SaveChanges(); } }
public override string Execute() { // DeductFee <Account number> if (this.CommandArgs.Length != 1) { throw new ArgumentException(OutputMessages.InvalidInput); } if (!this.AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(OutputMessages.UserShouldLogIn); } var accountNumber = this.CommandArgs[0]; decimal currentBalance; using (var context = new BankSystemDbContext()) { var user = this.AuthenticationManager.GetCurrentUser(); context.Users.Attach(user); var checkingAccount = user .CheckingAccounts .FirstOrDefault(a => a.AccountNumber == accountNumber); if (checkingAccount == null) { throw new ArgumentException(OutputMessages.InvalidAccount); } checkingAccount.DeductFee(); currentBalance = checkingAccount.Balance; context.SaveChanges(); } return(string.Format(OutputMessages.DeductedFee, accountNumber, currentBalance)); }
public AddInterestCommand(BankSystemDbContext database, string[] commandArgs) : base(database, commandArgs) { }
public CardService(BankSystemDbContext context, ICardHelper cardHelper) : base(context) { this.cardHelper = cardHelper; }
protected BaseService(BankSystemDbContext context) { this.Context = context; }
public ExitCommand(BankSystemDbContext context, string[] args) : base(context, args) { }
private static void PrepareDatabase(BankSystemDbContext database) { database.Database.EnsureDeleted(); database.Database.EnsureCreated(); }
public ListAccountsCommand(BankSystemDbContext database, string[] commandArgs) : base(database, commandArgs) { }
public CommandInterpreter(BankSystemDbContext database) { this.database = database; }
public ListAccountsCommand(BankSystemDbContext context, string[] args) : base(context, args) { }
public BankAccountService(BankSystemDbContext context, IBankAccountUniqueIdHelper uniqueIdHelper) : base(context) { this.uniqueIdHelper = uniqueIdHelper; }
public DeductFeeCommand(BankSystemDbContext database, string[] commandArgs) : base(database, commandArgs) { }