public CadastroMenu ReadById(int id) { CadastroMenu menu = new CadastroMenu(); try { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = "SELECT * FROM Menu WHERE id=@menuId "; comando.Parameters.AddWithValue("@menuId", id); SqlDataReader dr = ConexaoBanco.Selecionar(comando); if (dr.HasRows) { dr.Read(); menu.nome = Convert.ToString(dr["nome"]); menu.url = Convert.ToString(dr["url"]); menu.ordem = Convert.ToInt32(dr["ordem"]); menu.codigoPai = Convert.ToInt32(dr["codigoPai"]); menu.id = Convert.ToInt32(dr["id"]); } } catch { menu = null; throw; } return(menu); }
public Dictionary <int, CadastroMenu> ListarPorFiltroGrupo(List <GrupoUsuario> grupos) // retorna uma lista de links/itens de menu filtrado por 2 ou mais grupos de usuario { // List<CadastroMenu> ListaDelinks = null; Dictionary <int, CadastroMenu> conjunto = new Dictionary <int, CadastroMenu>(); try { foreach (var grupo in grupos) { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = "SELECT [ExtranetFenix].[dbo].menu.* FROM [ExtranetFenix].[dbo].[grupoXMenu] JOIN [ExtranetFenix].[dbo].menu on [ExtranetFenix].[dbo].grupoXMenu.Menu_fk = [ExtranetFenix].[dbo].menu.id where [ExtranetFenix].[dbo].[grupoXMenu].grupoUsuario_fk = @idGrupo"; comando.Parameters.AddWithValue("@idGrupo", grupo.id); SqlDataReader dr = ConexaoBanco.Selecionar(comando); if (dr.HasRows) { CadastroMenu link = new CadastroMenu(); while (dr.Read()) { link.id = Convert.ToInt32(dr["id"]); link.nome = Convert.ToString(dr["nome"]); link.ordem = Convert.ToInt32(dr["ordem"]); link.codigoPai = Convert.ToInt32(dr["codigoPai"]); link.url = Convert.ToString(dr["URL"]); if (!conjunto.ContainsKey(link.id)) { conjunto.Add(link.id, link); } link = new CadastroMenu(); } } } } catch (Exception e) { conjunto = null; throw e; } return(conjunto); }
public void Gravar(CadastroMenu cadastroMenu) { CadastroMenuDAO cadastroMenuDAO = new CadastroMenuDAO(); if (cadastroMenu.id != 0) { //altera cadastroMenuDAO.Update(cadastroMenu); } else { //insere cadastroMenuDAO.Insert(cadastroMenu); } }
public ActionResult AdicionarLinks(String link) { CadastroMenu cm = JsonConvert.DeserializeObject <CadastroMenu>(link); if (cm.nome != "" && cm.url != "") { CadastroMenuBO cmBO = new CadastroMenuBO(); cmBO.Gravar(cm); } return(View()); }
public void Insert(CadastroMenu menu) // responsavel po inserir um link para ser usado como item de menu { try { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = "INSERT INTO Menu (nome,url,ordem,codigoPai) values(@nome,@url,@ordem,@codigoPai) "; comando.Parameters.AddWithValue("@url", menu.url); comando.Parameters.AddWithValue("@ordem", menu.ordem); comando.Parameters.AddWithValue("@nome", menu.nome); comando.Parameters.AddWithValue("@codigoPai", menu.codigoPai); ConexaoBanco.CRUD(comando); } catch { throw; } }
public void Update(CadastroMenu menu) { try { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = "UPDATE Menu SET nome=@nome, url=@url, ordem=@ordem,codigoPai=@codigoPai WHERE id=@menuId "; comando.Parameters.AddWithValue("@nome", menu.nome); comando.Parameters.AddWithValue("@url", menu.url); comando.Parameters.AddWithValue("@ordem", menu.ordem); comando.Parameters.AddWithValue("@codigoPai", menu.codigoPai); comando.Parameters.AddWithValue("@menuId", menu.id); ConexaoBanco.CRUD(comando); } catch { throw; } }
public IList <CadastroMenu> ListarTodosLinks() //retorna um lista de links/itens de menu { IList <CadastroMenu> menus = new List <CadastroMenu>(); try { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = "SELECT * FROM Menu "; SqlDataReader dr = ConexaoBanco.Selecionar(comando); if (dr.HasRows) { while (dr.Read()) { CadastroMenu menucadastro = new CadastroMenu(); menucadastro.nome = Convert.ToString(dr["nome"]); menucadastro.url = Convert.ToString(dr["url"]); menucadastro.ordem = Convert.ToInt32(dr["ordem"]); menucadastro.codigoPai = Convert.ToInt32(dr["codigoPai"]); menucadastro.id = Convert.ToInt32(dr["id"]); menus.Add(menucadastro); } } } catch { menus = null; throw; } return(menus); }