public async Task <ActionResult> PostTipoInstrumento(IFormCollection data)
        {
            int    code;
            string message;

            try
            {
                //Guardar objeto en la base de datos
                TipoInstrumento ti = new TipoInstrumento()
                {
                    Codigo      = data["codigo"],
                    Descripcion = data["descripcion"]
                };

                _context.TipoInstrumento.Add(ti);
                await _context.SaveChangesAsync();

                code    = 1;
                message = "OK";

                return(Ok(new { code, message }));
            }
            catch (Exception ex)
            {
                code    = -1;
                message = "ERROR " + ex.Message;
                return(Ok(new { code, message }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> PutTipoInstrumento(long id, TipoInstrumento tipoInstrumento)
        {
            if (id != tipoInstrumento.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tipoInstrumento).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TipoInstrumentoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <TipoInstrumento> > PostTipoInstrumento(TipoInstrumento tipoInstrumento)
        {
            _context.TipoInstrumento.Add(tipoInstrumento);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTipoInstrumento", new { id = tipoInstrumento.Id }, tipoInstrumento));
        }
        public async Task <ActionResult> EditTipoInstrumento(IFormCollection data)
        {
            int    code;
            string message;

            try
            {
                //Capturar ID del equipo a editar
                long id_td = long.Parse(data["id"]);

                //Buscar el equipo en la base de datos
                TipoInstrumento tdEdit = _context.TipoInstrumento.Where(i => i.Id == id_td).FirstOrDefault();

                if (tdEdit != null)
                {
                    //mapear nuevos datos
                    tdEdit.Id          = id_td;
                    tdEdit.Descripcion = data["descripcion"];
                    tdEdit.Codigo      = data["codigo"];

                    _context.Entry(tdEdit).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    code    = 1;
                    message = "OK";
                }
                else
                {
                    code    = 0;
                    message = "Tipo instrumento a editar inválido";
                }

                return(Ok(new { code, message }));
            }
            catch (Exception ex)
            {
                code    = -1;
                message = "ERROR " + ex.ToString();
                return(Ok(new { code, message }));
            }
        }
Exemple #5
0
        public static List <TipoInstrumento> ObtenerListaTipos()
        {
            List <TipoInstrumento> resultado = new List <TipoInstrumento>();
            string        consulta           = "SELECT * FROM tipo_instrumento";
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["CadenaBD"].ToString());

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Parameters.Clear();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = consulta;

                SqlDataReader dr = cmd.ExecuteReader();

                if (dr != null)
                {
                    while (dr.Read())
                    {
                        TipoInstrumento aux = new TipoInstrumento();
                        aux.Id   = int.Parse(dr["id"].ToString());
                        aux.Tipo = dr["tipo"].ToString();
                        resultado.Add(aux);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(resultado);
        }
Exemple #6
0
 //constructor con parametros
 public Instrumento(string nombre, TipoInstrumento instTipo)
 {
     this.nombre = nombre;
     this.tipo   = instTipo;
 }
Exemple #7
0
 public void setTipo(TipoInstrumento tipo)
 {
     this.tipo = tipo;
 }