public async Task <IActionResult> Edit(ClaimTransactionViewModel viewModel) { if (ModelState.IsValid) { ClaimTransaction claimTransaction = new ClaimTransaction(); claimTransaction = viewModel.ClaimTransaction; claimTransaction.TaxAmount = TaxAmount(claimTransaction.Taxable, claimTransaction.Amount, claimTransaction.ClaimNumber); try { _context.Update(claimTransaction); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { claimId = claimTransaction.ClaimNumber })); } catch (DbUpdateException ex) { ModelState.AddModelError(string.Empty, ex.InnerException.Message.ToString()); } } viewModel.AccountList = new SelectList(_context.AccountCharts, "ID", "AccountCode", viewModel.ClaimTransaction.AccountID); viewModel.AffectedList = new SelectList(_context.Affecteds, "ID", "Name", viewModel.ClaimTransaction.AffectedID); viewModel.PayeeList = new SelectList(_context.Payees, "ID", "Name", viewModel.ClaimTransaction.PayeeID); viewModel.TransactionTypeList = new SelectList(_context.TransactionTypes, "ID", "Name", viewModel.ClaimTransaction.TransactionTypeID); return(View(viewModel)); }
// GET: ClaimTransactions/Edit/5 public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var claimTransaction = await _context.ClaimTransactions.SingleOrDefaultAsync(m => m.ID == id); if (claimTransaction == null) { return(NotFound()); } ClaimTransactionViewModel viewModel = new ClaimTransactionViewModel { ClaimTransaction = claimTransaction, AccountList = new SelectList(_context.AccountCharts, "ID", "AccountCode", claimTransaction.AccountID), AffectedList = new SelectList(_context.Affecteds, "ID", "Name", claimTransaction.AffectedID), PayeeList = new SelectList(_context.Payees, "ID", "Name", claimTransaction.PayeeID), TransactionTypeList = new SelectList(_context.TransactionTypes, "ID", "Name", claimTransaction.TransactionTypeID) }; return(View(viewModel)); }
// GET: ClaimTransactions/Create public async Task <IActionResult> Create(Guid productId, Guid clientId, Guid policyId, int claimNumber) { ClaimTransaction claimtransaction = new ClaimTransaction { ClaimNumber = claimNumber, Taxable = true, TaxAmount = 0, RequisitionDate = DateTime.Now, InvoiceDate = DateTime.Now }; ClaimTransactionViewModel viewModel = new ClaimTransactionViewModel { ProductID = productId, ClientID = clientId, PolicyID = policyId, ClaimNumber = claimNumber, ClaimTransaction = claimtransaction, PayeeList = new SelectList(await _context.Payees .AsNoTracking() .OrderBy(p => p.Name).ToListAsync(), "ID", "Name"), AccountList = new SelectList(await _context.AccountCharts .AsNoTracking() .OrderBy(p => p.AccountCode).ToListAsync(), "ID", "AccountCode"), AffectedList = new SelectList(await _context.Affecteds .AsNoTracking().ToListAsync(), "ID", "Name"), TransactionTypeList = new SelectList(await _context.TransactionTypes .AsNoTracking().ToListAsync(), "ID", "Name") }; return(View(viewModel)); }
public async Task <IActionResult> Create(ClaimTransactionViewModel viewModel) { var invoiceNumber = viewModel.ClaimTransaction.InvoiceNumber; var currentProductId = viewModel.ProductID; var currentClientId = viewModel.ClientID; var currentPolicyId = viewModel.PolicyID; var currentClaimNumber = viewModel.ClaimTransaction.ClaimNumber; try { if (ModelState.IsValid) { ClaimTransaction claimTransaction = new ClaimTransaction(); TransactionNumbers transactionnumber = new TransactionNumbers(); claimTransaction = viewModel.ClaimTransaction; claimTransaction.ID = Guid.NewGuid(); claimTransaction.ClaimNumber = viewModel.ClaimNumber; claimTransaction.TransactionNumber = transactionnumber.GetTransactionNumber(_context); claimTransaction.TaxAmount = TaxAmount(claimTransaction.Taxable, claimTransaction.Amount, claimTransaction.ClaimNumber); _context.Add(claimTransaction); await _context.SaveChangesAsync(); var tranParam = claimTransaction.TransactionNumber; await _context.Database.ExecuteSqlCommandAsync( "INSERT INTO ClaimTransactionGenerator(TransactionNumber) " + "Values ({0})", parameters : tranParam); return(RedirectToAction("Index", new { productId = currentProductId, clientId = currentClientId, policyId = currentPolicyId, claimId = currentClaimNumber })); } } catch (DbUpdateException ex) { var errorMsg = ex.InnerException.Message.ToString(); viewModel.ErrMsg = errorMsg; if (errorMsg.Contains("IX_ClaimTransaction_InvoiceNumber")) { viewModel.ErrMsg = $"Duplicate Invoice Number {invoiceNumber} exists."; ModelState.AddModelError(string.Empty, viewModel.ErrMsg); } ModelState.AddModelError(string.Empty, ex.InnerException.Message.ToString()); } viewModel.PayeeList = new SelectList(await _context.Payees.OrderBy(p => p.Name) .AsNoTracking() .ToListAsync(), "ID", "Name", viewModel.ClaimTransaction.ID); viewModel.AccountList = new SelectList(await _context.AccountCharts .AsNoTracking() .OrderBy(p => p.AccountCode).ToListAsync(), "ID", "AccountCode", viewModel.ClaimTransaction.AccountID); viewModel.AffectedList = new SelectList(await _context.Affecteds .AsNoTracking() .OrderBy(p => p.Name).ToListAsync(), "ID", "Name", viewModel.ClaimTransaction.AffectedID); viewModel.TransactionTypeList = new SelectList(await _context.TransactionTypes .AsNoTracking() .OrderByDescending(p => p.Name).ToListAsync(), "ID", "Name", viewModel.ClaimTransaction.TransactionTypeID); return(View(viewModel)); }