コード例 #1
0
        public AlumnoResponse Delete(FiltroComunRequest request)
        {
            var response = new AlumnoResponse();

            try
            {
                using (var ctx = new ContextoDb())
                {
                    var entidad = ctx.GetAlumno(request.Id);

                    if (entidad == null)
                    {
                        throw new InvalidOperationException("Registro no existe");
                    }

                    ctx.Set <Alumno>().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);
        }
コード例 #2
0
        public AlumnoResponse Get(FiltroComunRequest request)
        {
            var response = new AlumnoResponse();

            try
            {
                using (var ctx = new ContextoDb())
                {
                    var entidad = ctx.GetAlumno(request.Id);
                    if (entidad == null)
                    {
                        throw new InvalidOperationException("No se encuentra el registro");
                    }

                    response.Alumno = new AlumnoDto
                    {
                        Id                = entidad.Id,
                        Nombres           = entidad.Nombres,
                        Apellidos         = entidad.Apellidos,
                        CorreoElectronico = entidad.CorreoElectronico,
                        Edad              = entidad.Edad,
                        FechaNacimiento   = entidad.FechaNacimiento,
                    };
                }

                response.Exito = true;
            }
            catch (Exception ex)
            {
                response.Exito        = false;
                response.MensajeError = ex.Message;
            }

            return(response);
        }
コード例 #3
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);
        }