public CursoResponse Put([FromBody] CursoRequest value) { var response = new CursoResponse(); try { using (var ctx = new ContextoDb()) { var entidad = ctx.GetCurso(value.Id); if (entidad == null) { throw new InvalidOperationException("Registro no existe"); } entidad.NombreCurso = value.NombreCurso; entidad.NombreProfesor = value.NombreProfesor; entidad.FechaInicio = value.FechaInicio; ctx.Set <Curso>().Attach(entidad); ctx.Entry(entidad).State = EntityState.Modified; AsignarDto(response, entidad); response.Exito = ctx.SaveChanges() > 0; } } catch (Exception ex) { response.Exito = false; response.MensajeError = ex.Message; } return(response); }
public CursoResponse Delete(FiltroComunRequest request) { var response = new CursoResponse(); try { using (var ctx = new ContextoDb()) { var entidad = ctx.GetCurso(request.Id); if (entidad == null) { throw new InvalidOperationException("Registro no existe"); } ctx.Set <Curso>().Attach(entidad); ctx.Entry(entidad).State = EntityState.Deleted; response.Exito = ctx.SaveChanges() > 0; } } catch (Exception ex) { response.Exito = false; response.MensajeError = ex.Message; } return(response); }
public Usuario AutenticaUsuario(UsuarioAutenticacao dto) { var usuarioAutenticado = _contexto.UsuarioDb.Where(usuario => usuario.Email == dto.Email && usuario.Senha == dto.SenhaCriptografada && usuario.Ativo).FirstOrDefault(); if (usuarioAutenticado == null) { return(usuarioAutenticado); } _contexto.Entry(usuarioAutenticado).State = EntityState.Modified; _contexto.SaveChanges(); return(usuarioAutenticado); }
public ActionResult Edit([Bind(Include = "ProfessorId,Matricula,Nome,CPF,Email,Nascimento,Cadastro,Endereco")] Professor professor) { if (ModelState.IsValid) { db.Entry(professor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(professor)); }
public ActionResult Edit([Bind(Include = "ProgramaId,Nome,Descricao")] Programa programa) { if (ModelState.IsValid) { db.Entry(programa).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(programa)); }
public ActionResult Edit([Bind(Include = "AlunoId,Cadastro,Matricula,Nome,CPF,Email,Nascimento,Mae,Endereco")] Aluno aluno) { if (ModelState.IsValid) { db.Entry(aluno).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aluno)); }
public ActionResult Edit([Bind(Include = "CursoId,Nome,Codigo,Objetivos,Descricao,Programa")] Curso curso) { if (ModelState.IsValid) { db.Entry(curso).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(curso)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Nome,Sigla")] EstadoModels estadoModels) { if (ModelState.IsValid) { db.Entry(estadoModels).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(estadoModels)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Nome,Telefone,Email,Cpf,Endereco,CidadeId")] MembrosModel membrosModel) { if (ModelState.IsValid) { db.Entry(membrosModel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CidadeId = new SelectList(db.Cidades, "Id", "Nome", membrosModel.CidadeId); return(View(membrosModel)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Nome,EstadoId")] CidadeModels cidadeModels) { if (ModelState.IsValid) { db.Entry(cidadeModels).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.EstadoId = new SelectList(db.Estados, "Id", "Nome", cidadeModels.EstadoId); return(View(cidadeModels)); }
public T Modificar(T entidad, int key) { if (entidad == null) { return(null); } T existing = dbContexto.Set <T>().Find(key); if (existing != null) { dbContexto.Entry(existing).CurrentValues.SetValues(entidad); dbContexto.SaveChanges(); } return(existing); }
public Parceiro AutenticaParceiro(ParceiroAutenticacao dto) { var parceiroAutenticado = _contexto.ParceiroDb.Where(parceiro => parceiro.Email == dto.Email && parceiro.Senha == dto.SenhaCriptografada && parceiro.Ativo).FirstOrDefault(); if (parceiroAutenticado == null) { return(parceiroAutenticado); } _contexto.Entry(parceiroAutenticado).State = EntityState.Modified; _contexto.SaveChanges(); return(parceiroAutenticado); }
private void botonModificarMateria_Click(object sender, EventArgs e) { Materia materiaModificado = new Materia(); materiaModificado.Nombre = entradaNombreMateria.Text; materiaModificado.CodigoMateria = entradaCodigoMateria.Text; materiaModificado.Id = int.Parse(idMateriaSeleccionada); //7 agregue if (ValidarDatos(materiaModificado.CodigoMateria, materiaModificado, false)) { entradaCodigoMateria.Clear(); entradaNombreMateria.Clear(); Materia materiaBaseDatos = contextoDb.Materias.Find(materiaModificado.Id); if (materiaBaseDatos != null) { contextoDb.Entry(materiaBaseDatos).CurrentValues.SetValues(materiaModificado); contextoDb.SaveChanges(); } cargarListaMateria(); } }
private void botonModificarDocente_Click(object sender, EventArgs e) { Docente docenteModificado = new Docente(); docenteModificado.Nombre = entradaNombreDocente.Text; docenteModificado.Apellido = entradaApellidoDocente.Text; docenteModificado.Ci = entradaCIDocente.Text; docenteModificado.Id = int.Parse(idDocenteSeleccionado); if (ValidarDatos(docenteModificado.Ci, docenteModificado, false)) { mantenimientoDocente.ModificarDocente(idDocenteSeleccionado, docenteModificado); entradaCIDocente.Clear(); entradaApellidoDocente.Clear(); entradaNombreDocente.Clear(); Docente docenteBaseDatos = contextoDb.Docentes.Find(docenteModificado.Id); if (docenteBaseDatos != null) { contextoDb.Entry(docenteBaseDatos).CurrentValues.SetValues(docenteModificado); contextoDb.SaveChanges(); } cargarListaDocente(); } }
public AlumnoResponse Put([FromBody] AlumnoRequest value) { var response = new AlumnoResponse(); try { using (var ctx = new ContextoDb()) { var entidad = ctx.GetAlumno(value.Id); if (entidad == null) { throw new InvalidOperationException("Registro no existe"); } entidad.Nombres = value.Nombres; entidad.Apellidos = value.Apellidos; entidad.CorreoElectronico = value.CorreoElectronico; entidad.Edad = value.Edad; entidad.FechaNacimiento = value.FechaNacimiento; ctx.Set <Alumno>().Attach(entidad); ctx.Entry(entidad).State = EntityState.Modified; AsignarDto(response, entidad); response.Exito = ctx.SaveChanges() > 0; } } catch (Exception ex) { response.Exito = false; response.MensajeError = ex.Message; } return(response); }
public void Atualizar(TEntity obj) { _contexto.Entry(obj).State = EntityState.Modified; }
public string AlterarEndereco(Endereco endereco) { endereco.DataAlteracao = DateTime.Now; _contexto.Entry(endereco).State = EntityState.Modified; return(MensagensGlobal.EdicaoSucesso); }