public async Task <IActionResult> InterestProcess() { List <ActivityType> AllInterests = new List <ActivityType>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:44386/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ViewBag.country = ""; HttpResponseMessage response = await client.GetAsync("https://localhost:44386/api/ActivityTypes"); if (response.IsSuccessStatusCode) { var details = await response.Content.ReadAsAsync <IEnumerable <ActivityType> >(); var ActivitiesList = details.ToList(); AllInterests = ActivitiesList; } else { } } var model = new InterestModel { AvailableInterestTypes = getInterestTypes(AllInterests) }; return(View(model)); }
public IActionResult Interest([FromBody] InterestModel model) { InterestDTO dto = Mapping.Mapper.Map <InterestModel, InterestDTO>(model); _curriculumService.AddOrUpdateSectionBlock <InterestDTO>(dto, model.FormMode, SectionNames.Interest); return(Ok(new { id = model.InterestId })); }
private void Generate() { InterestModel i = (InterestModel)cboPaymentTerm.SelectedItem; string term = i.Description; int duration = int.Parse(txtDuration.Text); double interestRate = i.Rate; decimal principal = decimal.Parse(txtPrincipal.Text); double rate = interestRate / 100; decimal interest = principal * (decimal)rate; decimal amount = principal / duration; decimal maturityValue = interest + principal; decimal perRemit = maturityValue / duration; string[] tokens = txtEffectiveDate.Text.Split('/'); DateTime date = new DateTime(int.Parse(tokens[2]), int.Parse(tokens[0]), int.Parse(tokens[1])); string token = txtId.Text.Substring(4); string maturityDate = ConvertDate(generateMaturityDate(term, date, duration)); loan.BorrowerId = int.Parse(token); loan.CollectorId = user.Id; loan.PrincipalLoan = principal; loan.InterestId = i.Id; loan.Interest = interest; loan.MaturityValue = maturityValue; loan.PerRemittance = perRemit; loan.Duration = duration; loan.EffectiveDate = date; loan.TotalBalance = maturityValue; string[] tokens2 = maturityDate.Split('/'); DateTime date2 = new DateTime(int.Parse(tokens2[2]), int.Parse(tokens2[0]), int.Parse(tokens[1])); loan.MaturityDate = date2; txtInterest.Text = interest.ToString("c"); txtPerRemittance.Text = perRemit.ToString("c"); txtMaturityValue.Text = maturityValue.ToString("c"); decimal balance = 0; if (operation != "view") { txtTotalBalance.Text = maturityValue.ToString(); balance = maturityValue; } else { balance = Convert.ToDecimal(txtTotalBalance.Text.Substring(0)); } txtMaturityDate.Text = maturityDate; GenerateLedger(term, date, duration, amount, perRemit - amount, maturityValue, balance); isGenerated = true; }
public static InterestModel CreateInterest(InterestModel interestModel) { using (var _context = new bbbsDbContext()) { var newInterest = _context.Add(new Interest { InterestName = interestModel.InterestName }); _context.SaveChanges(); interestModel.Id = newInterest.Entity.Id; return(interestModel); } }
public async void FillSummary() { lstSummary.Items.Clear(); IEnumerable <ILoanModel> loans = await loanObj.GetAll(); if (cboYear.SelectedIndex != -1 || cboMonth.SelectedIndex != -1 || cboPaymentTerm.SelectedIndex != -1 || cboCollector.SelectedIndex != -1) { loans = await loanObj.GetAll(); if (cboYear.SelectedIndex != -1) { int year = int.Parse(cboYear.SelectedItem.ToString()); loans = loans.Where(l => l.EffectiveDate.Year == year); } if (cboMonth.SelectedIndex != -1) { int month = cboMonth.SelectedIndex + 1; loans = loans.Where(l => l.EffectiveDate.Month == month); } if (cboCollector.SelectedIndex != -1) { UserModel user = (UserModel)cboCollector.SelectedItem; loans = loans.Where(l => l.Collector.ToLower() == user.Name.ToLower()); } if (cboPaymentTerm.SelectedIndex != -1) { InterestModel _i = (InterestModel)cboPaymentTerm.SelectedItem; loans = loans.Where(l => l.PaymentTerm.ToLower() == _i.Description.ToLower()); } } FillListView(loans); //add to statuses decimal totalPrincipal = 0; decimal totalInterest = 0; int numOfLoans = 0; foreach (LoanModel l in loans) { totalPrincipal += l.PrincipalLoan; totalInterest += l.Interest; numOfLoans += 1; } lblTotalPrincipal.Text = totalPrincipal.ToString("c"); lblTotalInterest.Text = totalInterest.ToString("c"); lblNumOfLoans.Text = numOfLoans.ToString(); }
public IActionResult InterestProcess(InterestModel model) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var usercurrent = _context.Customers.Where(c => c.IdentityUserId == userId).SingleOrDefault(); if (_context.Interests.Where(c => c.CustomerID == usercurrent.CustomerID) == null) { List <string> listOfInterestTypes = model.SelectedInterests.ToList(); foreach (string item in listOfInterestTypes) { var SelectedInterest = new Interest() { ActivityType = item, CustomerID = usercurrent.CustomerID }; _context.Interests.Add(SelectedInterest); _context.SaveChanges(); } return(RedirectToAction(nameof(Index))); } else { var customersInterests = _context.Interests.Where(c => c.CustomerID == usercurrent.CustomerID); foreach (var item in customersInterests) { _context.Interests.Remove(item); } List <string> listOfInterestTypes = model.SelectedInterests.ToList(); foreach (string item in listOfInterestTypes) { var SelectedInterest = new Interest() { ActivityType = item, CustomerID = usercurrent.CustomerID }; _context.Interests.Add(SelectedInterest); _context.SaveChanges(); } return(RedirectToAction(nameof(Index))); } }
public void Interest() { using (var context = new BankDbContext(options)) { int id = 8; decimal interest = 0.135m; DateTime now = DateTime.Now; DateTime latestInterest = now.AddDays(-365); decimal balance = 100m; decimal expected = 113.5m; var model = new InterestModel() { AccountId = id }; var account = new Account() { AccountId = id, Balance = balance }; context.Accounts.Add(account); context.SaveChanges(); new InterestCommand().RunAsync(context, model, latestInterest, interest).Wait(); int numOfTransactions = context.Transactions .Where(t => t.AccountId == account.AccountId || t.AccountId == account.AccountId) .Count(); var createdAccount1 = context.Accounts.Single(a => a.AccountId == id); // Check balance Assert.Equal(expected, createdAccount1.Balance); // Checks so that a transaction was made Assert.Equal(1, numOfTransactions); } }