public async Task <IActionResult> AddorEdit(int id, [Bind("TransactionID,AcountNumber,BeneficiaryName,BankName,SWIFTCode,Ammount,Date")] TransactionModel transactionModel) { if (ModelState.IsValid) { if (id == 0) { transactionModel.Date = DateTime.Now; _context.Add(transactionModel); await _context.SaveChangesAsync(); } else { try { _context.Update(transactionModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionModelExists(transactionModel.TransactionID)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazerViewToString(this, "_ViewAll", _context.Transactions.ToList()) })); } return(Json(new { isValid = false, html = Helper.RenderRazerViewToString(this, "AddOrEdit", transactionModel) })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Type,Date,Amount,Memo")] TransactionModel transactionModel) { if (id != transactionModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(transactionModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionModelExists(transactionModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(transactionModel)); }
public async Task <IActionResult> AddOrEdit(int id, [Bind("EmpleadoId,TipoDocumentoId,NumeroDocumento,Nombres,Apellidos,AreaId,FechaNacimiento")] EmpleadoModel empleadoModel) { if (ModelState.IsValid) { //Insert if (id == 0) { empleadoModel.FechaCreacion = DateTime.Now; _context.Add(empleadoModel); await _context.SaveChangesAsync(); } //Update else { try { //empleadoModel.FechaNacimiento = Convert.ToDate(empleadoModel.FechaNacimiento.ToString("dd/MM/yyyy")); empleadoModel.FechaCreacion = DateTime.Now; _context.Update(empleadoModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionModelExists(empleadoModel.EmpleadoId)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.Empleado.ToList()) })); } return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", empleadoModel) })); }