コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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));
 }
コード例 #5
0
 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));
 }
コード例 #6
0
 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));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
        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));
        }
コード例 #9
0
ファイル: MembrosController.cs プロジェクト: ArthurFritz/SGMI
        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));
        }
コード例 #10
0
ファイル: CidadeController.cs プロジェクト: ArthurFritz/SGMI
        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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
        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);
        }
コード例 #16
0
 public void Atualizar(TEntity obj)
 {
     _contexto.Entry(obj).State = EntityState.Modified;
 }
コード例 #17
0
 public string AlterarEndereco(Endereco endereco)
 {
     endereco.DataAlteracao          = DateTime.Now;
     _contexto.Entry(endereco).State = EntityState.Modified;
     return(MensagensGlobal.EdicaoSucesso);
 }