public async Task <IActionResult> Guardar(TarjetaViewModel entidad) { if (!ModelState.IsValid) { return(View("Editar", entidad)); } if (entidad.Id == 0) { await _service.CreateAsync(entidad); } else { await _service.EditAsync(entidad); } /* --------------------------- para mongodb registro bitacora */ var bitacora = new BitacoraViewModel() { fecha = DateTime.Now, Entidad = "Tarjeta", Accion = "Crear/Editar", Detalle = entidad.Id.ToString() }; await _bitacoraService.Create(bitacora); /* --------------------------- para mongodb registro bitacora */ return(RedirectToAction("Lista")); }
public async Task <IActionResult> Editar(int id) { TarjetaViewModel view = null; if (id == 0) { view = new TarjetaViewModel() { Expiracion = DateTime.Now.Date }; } else { view = await _service.GetByIdAsync(id); } /* --------------------------- para mongodb registro bitacora */ var bitacora = new BitacoraViewModel() { fecha = DateTime.Now, Entidad = "Tarjeta", Accion = "Editar", Detalle = id.ToString() }; await _bitacoraService.Create(bitacora); /* --------------------------- para mongodb registro bitacora */ return(View(view)); }
public ActionResult AddTarjeta(TarjetaViewModel tar) { try { if (ModelState.IsValid) { RepoDapper TarRepo = new RepoDapper(); tar.UserId = User.Identity.GetUserId(); TarRepo.CrearTarjeta(tar); ViewBag.Message = "La tarjeta se agrego."; } return(RedirectToAction("Index")); } catch { ViewBag.Message = "La tarjeta no se agrego."; return(View()); } }
//Falta probar que funcione bien desde aqui public void CrearTarjeta(TarjetaViewModel tar) { try { connection(); con.Open(); var parameters = new { @nombre = tar.Nombre, @numero = tar.Numero, @fecha = tar.Fecha, @codigo = tar.Codigo, @userid = tar.UserId, @id = tar.id }; con.Execute("dbo.CrearTarjeta", parameters, commandType: CommandType.StoredProcedure); con.Close(); } catch (Exception ex) { throw ex; } }
public async Task EditAsync(TarjetaViewModel tarjeta) { await PutAsync($"tarjeta/{tarjeta.Id}", tarjeta).ConfigureAwait(false); }
public async Task CreateAsync(TarjetaViewModel tarjeta) { await PostAsync("tarjeta", tarjeta).ConfigureAwait(false); }