public async Task <IActionResult> Edit(LossAdjusterViewModel viewModel) { if (ModelState.IsValid) { try { LossAdjuster lossAdjuster = new LossAdjuster(); lossAdjuster = viewModel.LossAdjuster; _context.Update(lossAdjuster); await _context.SaveChangesAsync(); var payeeParams = new object[] { lossAdjuster.ID, lossAdjuster.Name }; await _context.Database.ExecuteSqlCommandAsync( "UPDATE Payee SET Name = {0} WHERE PayeeItemID = {1}", parameters : payeeParams); return(RedirectToAction("Index", new { payeeclassId = viewModel.LossAdjuster.PayeeClassID })); } catch (DbUpdateException ex) { var errorMsg = ex.InnerException.Message.ToString(); viewModel.ErrMsg = errorMsg; ModelState.AddModelError(string.Empty, viewModel.ErrMsg); } } return(View(viewModel)); }
// GET: LossAdjusters/Edit/5 public async Task <IActionResult> Edit(Guid Id) { LossAdjusterViewModel viewModel = new LossAdjusterViewModel { LossAdjuster = await _context.LossAdjusters.SingleOrDefaultAsync(m => m.ID == Id) }; return(View(viewModel)); }
public async Task <IActionResult> Create(LossAdjusterViewModel viewModel) { if (ModelState.IsValid) { LossAdjuster lossAdjuster = new LossAdjuster(); lossAdjuster = viewModel.LossAdjuster; lossAdjuster.ID = Guid.NewGuid(); _context.Add(lossAdjuster); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { payeeclassId = viewModel.LossAdjuster.PayeeClassID })); } return(View(viewModel)); }
// GET: LossAdjusters/Create public IActionResult Create(int payeeClassId) { LossAdjuster lossAdjuster = new LossAdjuster { PayeeClassID = payeeClassId }; LossAdjusterViewModel viewModel = new LossAdjusterViewModel { LossAdjuster = lossAdjuster }; return(View(viewModel)); }