예제 #1
0
        private void _Salvar(Models.Editoras entidade)
        {
            string stringConexao = @"Data Source=den1.mssql1.gear.host;Initial Catalog=biblioteca4;user Id=biblioteca4;Password=Ga6g!w8m88_L";

            using (var conn = new SqlConnection(stringConexao))
            {
                var lista = CriarListaEditoras();
                if (entidade.id > 0)
                {
                    lista = _Excluir(entidade.id);
                }
                else
                {
                    entidade.id = lista.Count == 0
                        ? 1
                        : lista.OrderByDescending(item => item.id).FirstOrDefault().id + 1;
                }
                string     sql = "INSERT INTO Editoras (id,Nome) VALUES (@id,@Nome)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", entidade.id);
                cmd.Parameters.AddWithValue("@Nome", entidade.Nome);
                //cmd.Parameters.AddWithValue("@Tipo", entidade.);
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
예제 #2
0
        public Editoras GetByCodigo(int id)
        {
            var livro = new Models.Editoras();

            using (var db = new SeminarioVDbContext())
            {
                livro = db.Editoras
                        .Where(b => b.Id == id)
                        .FirstOrDefault();
            }
            return(livro);
        }
예제 #3
0
        private List <Models.Editoras> CriarListaEditoras()
        {
            //var lista = Session["Empregados"] as List<Models.Empregados>;
            string stringConexao         = @"Data Source=den1.mssql1.gear.host;Initial Catalog=biblioteca4;user Id=biblioteca4;Password=Ga6g!w8m88_L";
            string sql                   = "Select id,Nome From Editoras";
            List <Models.Editoras> lista = new List <Models.Editoras>();

            using (var conn = new SqlConnection(stringConexao))
            {
                var             cmd = new SqlCommand(sql, conn);
                Models.Editoras p   = null;
                try
                {
                    conn.Open();
                    using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (reader.Read())
                        {
                            p      = new Models.Editoras();
                            p.id   = (int)reader["id"];
                            p.Nome = reader["Nome"].ToString();
                            lista.Add(p);
                        }
                    }
                }

                catch (Exception e)
                {
                    throw e;
                }
            }
            if (lista == null)
            {
                lista = new List <Models.Editoras>();
            }

            return(lista
                   .OrderBy(item => item.id)
                   .ToList());
        }
예제 #4
0
 public void Put(int id, [FromBody] Models.Editoras value)
 {
 }
예제 #5
0
 public void Post([FromBody] Models.Editoras value)
 {
 }
예제 #6
0
        public ActionResult Salvar(Models.Editoras Editora)
        {
            _Salvar(Editora);

            return(Json(new { Sucesso = true }));
        }
 public IActionResult Put(int id, [FromBody] Models.Editoras value)
 {
     editora.Editar(value);
     return(Ok(value));
 }
 public IActionResult Post([FromBody] Models.Editoras value)
 {
     editora.Novo(value);
     return(Created("Criado", value));
 }