public ActionResult Create([Bind(Include = "OperationId,Type,Montant,Date,CompteId")] Operation operation) { try { if (ModelState.IsValid) { var compte = _db.Comptes.Find(operation.CompteId); if (operation.Type == TypeOperation.Retrait) { compte.SoldeBase = compte.SoldeBase - operation.Montant; } else { compte.SoldeBase = compte.SoldeBase + operation.Montant; } _db.Operations.Add(operation); _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CompteId = new SelectList(_db.Comptes, "CompteId", "CompteId", operation.CompteId); return(View(operation)); } catch (Exception) { return(RedirectToAction("Error")); } }
public override void Create(Client entity) { var client = entity ?? throw new ArgumentNullException(nameof(entity)); _db.Clients.Add(entity); _db.SaveChanges(); }
public T Add(T itemToAdd) { var entity = dbContext.Add <T>(itemToAdd); dbContext.SaveChanges(); return(entity.Entity); }
public IActionResult Process(float amount) { if (!CheckLoggedIn()) { return(RedirectToAction("Index", "Home")); } string userKey = (string)HttpContext.Session.GetString("CurrentUserKey"); Account userAccount = _context.Accounts.SingleOrDefault(e => e.UserKey == userKey); if (amount < 0 && userAccount.Balance < Math.Abs(amount)) { TempData["Error"] = "The Balance is insufficient."; return(RedirectToAction("Account", "Bank", new { userKey = userKey })); } else { Transaction newTransaction = new Transaction { Amount = amount, AccountID = userAccount.AccountID }; userAccount.Balance += amount; _context.Transactions.Add(newTransaction); _context.SaveChanges(); } return(RedirectToAction("Account", "Bank", new { userKey = userKey })); }
public bool UpdateUser(User user) { var item = _dbContext.Users.Where(a => a.Id == user.Id).FirstOrDefault(); item = user; _dbContext.SaveChanges(); return(true); }
public IHttpActionResult CreateClient([FromBody] Client client) { if (client == null) { return(BadRequest()); } _db.Clients.Add(client); _db.SaveChanges(); return(Ok()); }
public IHttpActionResult CreateIncident([FromBody] Incident incident) { if (incident == null) { return(BadRequest()); } _db.Incidents.Add(incident); _db.SaveChanges(); return(Ok()); }
public void WithdrawTooMuch() { using (var context = new BankDbContext(options)) { int id = 1; var model = new WithdrawModel() { AccountId = id, Amount = "200.00" }; var account = new Account() { AccountId = id, Balance = 100 }; context.Accounts.Add(account); context.SaveChanges(); new WithdrawCommand().RunAsync(context, model).Wait(); int numOfTransactions = context.Transactions.Where(t => t.AccountId == account.AccountId).Count(); var createdAccount = context.Accounts.Single(a => a.AccountId == id); // Check balance Assert.Equal(100, createdAccount.Balance); // Checks so that no transaction was made Assert.Equal(0, numOfTransactions); } }
// GET: Banques public ActionResult Index() { try { var banque = _db.Banque.Find("ENIT Bank"); var pm = from c in _db.PersonnesMorales select c; var pp = from c in _db.PersonnesPhysiques select c; var comptes = from c in _db.Comptes select c; var credits = from c in _db.Credits select c; if (banque == null) { return(HttpNotFound()); } banque.NbrComptes = Enumerable.Count(comptes); banque.NbrClients = Enumerable.Count(pm) + Enumerable.Count(pp); banque.NbrCredits = Enumerable.Count(credits); banque.ArgentDepose = comptes.Sum(i => i.SoldeBase); banque.SommeCredits = credits.Sum(i => i.MontantCredit); _db.SaveChanges(); return(View(banque)); } catch (Exception) { return(RedirectToAction("Error")); } }
private void doTransaction(object parameter) { if (Amount <= 0) { var message = new MessageDialog("Vrijednost ne moze biti negativna!"); message.ShowAsync(); } using (var db = new BankDbContext()) { BankAccount ba = db.BankAccounts.Where(b => b.BankAccountID == NumberToAccount).FirstOrDefault(); if (ba == null) { var message = new MessageDialog("Ne postoji racun sa tim brojem!"); message.ShowAsync(); } else { Transaction newTransaction = new Transaction(); newTransaction.Amount = Amount; newTransaction.FromAccount = Account; newTransaction.ToAccount = ba; newTransaction.TimeStamp = DateTime.Now; ba.Balance += Amount; Account.Balance -= Amount; db.Transactions.Add(newTransaction); _UserTransactions.Add(newTransaction); db.SaveChanges(); var message = new MessageDialog("Transakcija uspjesna!"); message.ShowAsync(); Balance = Account.Balance; } } }
private void addCreditTypebutton_Click(object sender, EventArgs e) { errorLabel.Text = String.Empty; if (String.IsNullOrWhiteSpace(depositTitleTextBox.Text)) { errorLabel.Text = "Fill the title."; return; } double interestRate; int days; try { interestRate = Convert.ToDouble(interestRateTextBox.Text); days = Convert.ToInt32(interestPeriodTextBox.Text); } catch { errorLabel.Text = "Fill the correct data."; return; } interestRate /= 100.0; DepositTypeEntity depositType = new DepositTypeEntity { DepositTitle = depositTitleTextBox.Text, InterestRate = interestRate, PayoutPeriod = days, PercentType = (PercentType)percentTypeComboBox.SelectedItem }; dbContext.DepositTypes.Add(depositType); dbContext.SaveChanges(); Close(); }
public void InsertInitialData() { using (var ctx = new BankDbContext()) { var newClient = new Clients { FirstName = "Bob", LastName = "Robertson", Birthday = DateTime.Parse("1964-04-04"), PhoneNamber = "+380 (067) 111 11 22" }; var card1 = new Cards { CardId = "5111111111111111", PinCode = "5551" }; newClient.Cards.Add(card1); var card2 = new Cards { CardId = "5111111111111112", PinCode = "5552" }; newClient.Cards.Add(card2); newClient.Address = new Addresses { ClientId = 1, Country = "Germany", State = "Mecklenburg-Vorpommern", Address = "544 Harry Place" }; ctx.Clients.Add(newClient); ctx.Operations.Add(new Operations { Amount = 200, InCard = card2, OutCard = card1 }); ctx.SaveChanges(); } }
private void PutMoneyButton_Click(object sender, EventArgs e) { errorLabel.Text = string.Empty; BankAccountEntity bankAccount; try { bankAccount = accountsDataGridView.SelectedRows[0].DataBoundItem as BankAccountEntity; bankAccount.MoneyCount += Convert.ToDecimal(getSetMoneyTextBox.Text); } catch { errorLabel.Text = "Invalid data."; return; } dbContext.BankAccounts.Update(bankAccount); dbContext.SaveChanges(); }
private void btn_BDebit_Click(object sender, RoutedEventArgs e) { BankDetails bd = new BankDetails(); var SumDebit = (from s in db.bnkdetails select s.AccountBalance).Sum(); BnkDebit_txt.Text = SumDebit.ToString(); bd.BankDebitBalance = BnkDebit_txt.Text; db.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Nom,Adresse,MatriculFiscal")] PersonneMorale personneMorale) { try { if (ModelState.IsValid) { _db.Clients.Add(personneMorale); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personneMorale)); } catch (Exception) { return(RedirectToAction("Error")); } }
public ActionResult Create( [Bind(Include = "Id,Nom,Adresse,Prénom,Cin,Profession,Telephone,Salaire")] PersonnePhysique personnePhysique) { try { if (ModelState.IsValid) { _db.Clients.Add(personnePhysique); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personnePhysique)); } catch (Exception) { return(RedirectToAction("Error")); } }
public ActionResult Create([Bind(Include = "CompteId,ClientId,Type,SoldeBase,DateOuverture")] Compte compte) { try { if (ModelState.IsValid) { _db.Comptes.Add(compte); _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(_db.Clients, "Id", "Nom", compte.ClientId); return(View(compte)); } catch (Exception) { return(RedirectToAction("Error")); } }
private void PutMoneyOnOpenedDepositButton_Click(object sender, EventArgs e) { errorLabel.Text = string.Empty; var selectedDeposit = userDepositsDataGridView.SelectedRows[0].DataBoundItem as UserDepositEntity; if (selectedDeposit == null) { errorLabel.Text = "Selected deposit is null."; return; } if (selectedDeposit.DepositType.DepositTitle != "Classic+") { errorLabel.Text = "You cant put money to opened classic deposit."; return; } decimal addSum; try { addSum = Convert.ToDecimal(addSymTextBox.Text); } catch { errorLabel.Text = "Invalid data."; return; } if (selectedDeposit.BankAccount.MoneyCount < addSum) { errorLabel.Text = "There is not enough money in this account."; return; } int t = (selectedDeposit.FinishDate - DateTimeOffset.Now).Days; decimal addedSumWithPersent = addSum * (decimal)((1 + t / Constants.K) * selectedDeposit.DepositType.InterestRate); selectedDeposit.CurrentBalance += addedSumWithPersent; selectedDeposit.BankAccount.MoneyCount -= addSum; dbContext.UserDeposits.Update(selectedDeposit); dbContext.SaveChanges(); }
public long CreateAccount(AccountDTO acc) { using (var db = new BankDbContext()) { Account a = mapper.Map <AccountDTO, Account>(acc); db.Account.Add(a); db.SaveChanges(); return(a.Id); } }
private void OpenCreditButton_Click(object sender, EventArgs e) { errorLabel.Text = String.Empty; if (_currentAccount == null) { errorLabel.Text = "Account not selected."; return; } DepositTypeEntity selectedDepositType; decimal startSum; try { selectedDepositType = (DepositTypeEntity)depositTypeComboBox.SelectedItem; startSum = Convert.ToDecimal(startSumTextBox.Text); } catch { errorLabel.Text = "Input correct data."; return; } if (_currentAccount.MoneyCount < startSum) { errorLabel.Text = "You don't have enough money."; return; } decimal currentBalance; if (selectedDepositType.PercentType == PercentType.Simple) { currentBalance = startSum * (decimal)(1 + ((double)selectedDepositType.PayoutPeriod / Constants.K) * selectedDepositType.InterestRate); } else { currentBalance = startSum * (decimal)Math.Pow((1 + selectedDepositType.InterestRate), ((double)selectedDepositType.PayoutPeriod / Constants.K)); } var userDepositEntity = new UserDepositEntity { BankAccountId = _currentAccount.Id, DepositTypeId = selectedDepositType.Id, StartDate = DateTimeOffset.Now, StartSum = startSum, FinishDate = DateTimeOffset.Now + TimeSpan.FromDays(selectedDepositType.PayoutPeriod), CurrentBalance = currentBalance }; _currentAccount.MoneyCount -= startSum; dbContext.BankAccounts.Update(_currentAccount); dbContext.UserDeposits.Add(userDepositEntity); dbContext.SaveChanges(); Close(); }
public bool DeleteAccount(long id) { using (var db = new BankDbContext()) { Account account = db.Account.FirstOrDefault(x => x.Id == id); account.Active = false; db.Entry(account).State = EntityState.Modified; db.SaveChanges(); return(true); } }
public ActionResult Create( [Bind(Include = "CreditId,MontantCredit,Planification,PayementMonsuel,ClientId")] Credit credit) { try { if (ModelState.IsValid) { _db.Credits.Add(credit); _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(_db.Clients, "Id", "Nom", credit.ClientId); return(View(credit)); } catch (Exception) { return(RedirectToAction("Error")); } }
public bool DeleteCustomer(long id) { using (var db = new BankDbContext()) { var customer = db.Customer.FirstOrDefault(x => x.ID == id); customer.Active = false; db.Entry(customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(true); }
/// <summary> /// Transfer cash between two card and update their balance. /// Default transfer it is withdraw cash. /// </summary> /// <param name="amount"></param> /// <param name="secondCard"></param> /// <returns></returns> public bool TrunsferCash(decimal amount, string secondCard = Constants.ATM) { Card inCard = _context.Cards.FirstOrDefault(x => x.CardId == secondCard); Card outCard = _context.Cards.FirstOrDefault(x => x.CardId == _cardsService.CurrentCardNumber); OperationsDetails inOperationDetails = new OperationsDetails(); OperationsDetails outOperationDetails = new OperationsDetails(); Operations operation = new Operations() { Amount = amount, InCard = inCard, InId = secondCard, OutCard = outCard, OutId = _cardsService.CurrentCardNumber, OperationDetailses = new List <OperationsDetails>() { inOperationDetails, outOperationDetails } }; inOperationDetails.Operations = operation; inOperationDetails.Amount = amount; inOperationDetails.Balance = inCard.Ballance + amount; inOperationDetails.OperationsType = _context.OperationsType.First(x => x.ID == 1); outOperationDetails.Operations = operation; outOperationDetails.Amount = amount; outOperationDetails.Balance = outCard.Ballance - amount; outOperationDetails.OperationsType = _context.OperationsType.First(x => x.ID == 2); inCard.Ballance += amount; outCard.Ballance -= amount; _context.Cards.Attach(inCard); _context.Cards.Attach(outCard); _context.Entry(inCard).State = EntityState.Modified; _context.Entry(outCard).State = EntityState.Modified; try { _context.Operations.Add(operation); _context.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public void RecalculateBallance(string cardNo) { using (var ctx = new BankDbContext()) { var card = ctx.Cards.SingleOrDefault(c => c.CardId == cardNo); ctx.Entry(card).Collection(c => c.InOperations).Load(); ctx.Entry(card).Collection(c => c.OutOperations).Load(); card.Ballance = card.InOperations.Sum(o => o.Amount) - card.OutOperations.Sum(o => o.Amount); ctx.SaveChanges(); } }
public long AddCustomer(CustomerDTO customerDTO) { using (var db = new BankDbContext()) { // or // IMapper mapper = new Mapper(config); // var customer = mapper.Map<customerDTO, Dest>(new Source()); Customer customer = mapper.Map <CustomerDTO, Customer>(customerDTO); db.Customer.Add(customer); db.SaveChanges(); return(customer.ID); } }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { GenerateKey generateKey = new GenerateKey(); User newUser = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Password = model.Password, UserKey = generateKey.RandKey() }; PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, newUser.Password); _context.Users.Add(newUser); _context.SaveChanges(); Account newAccount = new Account { Balance = 0, UserID = newUser.UserID, UserKey = newUser.UserKey }; _context.Accounts.Add(newAccount); _context.SaveChanges(); HttpContext.Session.SetString("CurrentUserKey", newUser.UserKey); return(RedirectToAction("Account", "Bank", new { UserKey = newUser.UserKey })); } return(View("Index")); }
private void Button_Click(object sender, RoutedEventArgs e) { var boundData = (Person)((Button)sender).DataContext; using (var db = new BankDbContext()) { var person = db.Persons.Where(x => x.AccoutnId == boundData.AccoutnId).FirstOrDefault(); person.Validated = true; db.SaveChanges(); viewModel.PenndingAccounts.Remove(boundData); listView_transactions.ItemsSource = null; var bind = new Binding(); bind.Source = viewModel.PenndingAccounts; this.listView_transactions.SetBinding(ListView.ItemsSourceProperty, bind); } }
private void doWork(object parameter) { if (Amount <= 0) { var message = new MessageDialog("Vrijednost ne moze biti negativna!"); message.ShowAsync(); } using (var db = new BankDbContext()) { BankAccount bTo = db.BankAccounts.Where(b => b.BankAccountID == AccountTo).FirstOrDefault(); BankAccount bFrom = db.BankAccounts.Where(b => b.BankAccountID == AccountFrom).FirstOrDefault(); if (bTo == null && (Trans == true || Dep == true)) { var message = new MessageDialog("Ne postoji racun sa tim brojem!(Prema)"); message.ShowAsync(); } else if (bFrom == null && (Trans == true || Rise == true)) { var message = new MessageDialog("Ne postoji racun sa tim brojem!(Sa)"); message.ShowAsync(); } else { Transaction newTransaction = new Transaction(); newTransaction.Amount = Amount; newTransaction.FromAccount = bFrom; newTransaction.ToAccount = bTo; newTransaction.TimeStamp = DateTime.Now; newTransaction.Referent = user; if (bTo != null) { bTo.Balance += Amount; } if (bFrom != null) { bFrom.Balance -= Amount; } db.Transactions.Add(newTransaction); _UserTransactions.Add(newTransaction); db.SaveChanges(); var message = new MessageDialog("Transakcija uspjesna!"); message.ShowAsync(); } } }
public IActionResult Confirm(Operation operation) { if (transfer.Lines.Count() == 0) { ModelState.AddModelError("", "Transfer form is empty"); } if (ModelState.IsValid) { operation.Lines = transfer.Lines.ToArray(); repository.SaveOperation(operation); // Input account number gets matched to existing object var obj = ctx.Accounts.FirstOrDefault(x => x.AccountNumber == operation.AccountNumber); if (obj != null) { obj.Balance += (decimal)operation.Amount; } ctx.SaveChanges(); //// This operations adds the new account according to input the user gives //ctx.AddRange(new Account //{ // AccountName = operation.AccountName, // AccountNumber = operation.AccountNumber, // Currency = "GEL", // Balance = (decimal)operation.Amount, // Category = "CurrentAccount" //}); //ctx.SaveChanges(); transfer.Clear(); return(RedirectToPage("/Completed", new { operationId = operation.OperationID })); } else { return(View()); } }