public async Task <IActionResult> LoadLoansConfirmed(LoanTempsViewModel viewModel) { Guid currentUserId = viewModel.UserID; Guid currentproductId = viewModel.ProductID; BulkHandles bulkhandle = new BulkHandles(); int newbulkhandle = bulkhandle.GetBulkHandle(_context); var loantemps = from p in _context.LoanTemps .Where(u => u.UserID == currentUserId) .Include(p => p.Component) .OrderBy(i => i.IDNumber) select p; int recCount = loantemps.Count(); foreach (var l in loantemps) { Loan loan = new Loan(); if (PolicyExists(l.IDNumber)) { var loanParams = new object[] { Guid.NewGuid(), GetPolicyId(l.IDNumber), l.ComponentID, l.AccountNumber, l.Term, l.Rate, l.LoanDate, l.Value, l.Premium, l.SettlementDate, newbulkhandle, DateTime.Now, currentUserId, null, null }; await _context.Database.ExecuteSqlCommandAsync( "INSERT INTO Loan(ID, PolicyID, ComponentID, AccountNumber, Term, Rate, LoanDate, " + "Value, Premium, SettlementDate, BulkHandle, DateAdded, AddedBy, DateModified, ModifiedBy) " + "Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14})", parameters : loanParams); } else { // Generate a log file and ask user to load on Client and Policy before loading premiums again. } } Guid myParam = currentUserId; await _context.Database.ExecuteSqlCommandAsync( "DELETE FROM LoanTemp WHERE UserID = {0}", parameters : myParam); var bulkParams = new object[] { newbulkhandle, "Loan", DateTime.Now, recCount, DateTime.Now, currentUserId }; await _context.Database.ExecuteSqlCommandAsync( "INSERT INTO BulkHandleGenerator(BulkNumber, TableName, BulkDate, RecordCount, DateAdded, AddedBy) " + "Values ({0}, {1}, {2}, {3}, {4}, {5})", parameters : bulkParams); return(RedirectToAction("ProductClients", "Products", new { productId = currentproductId })); }
// GET: Loans/LoadLoans public async Task <IActionResult> LoadLoans(Guid userId, Guid productId) { var loantemps = await(from p in _context.LoanTemps .Where(u => u.UserID == userId) .Include(p => p.Component) .OrderBy(i => i.IDNumber) select p).ToListAsync(); var loanTotal = loantemps.Sum(p => p.Value); var premiumTotal = loantemps.Sum(p => p.Premium); LoanTempsViewModel viewModel = new LoanTempsViewModel { LoanTemps = loantemps, ProductID = productId, UserID = userId, PremiumTotal = premiumTotal, LoanTotal = loanTotal, ComponentID = _context.LoanTemps.FirstOrDefault().ComponentID }; return(View(viewModel)); }