예제 #1
0
        public static LocalArmazenamentoModel RecuperarPeloId(int id)
        {
            LocalArmazenamentoModel ret = null;

            using (var conexao = new SqlConnection())
            {
                conexao.ConnectionString = ConfigurationManager.ConnectionStrings["principal"].ConnectionString;
                conexao.Open();
                using (var comando = new SqlCommand())
                {
                    comando.Connection  = conexao;
                    comando.CommandText = "select * from local_armazenamento where (id = @id)";

                    comando.Parameters.Add("@id", SqlDbType.Int).Value = id;

                    var reader = comando.ExecuteReader();
                    if (reader.Read())
                    {
                        ret = new LocalArmazenamentoModel
                        {
                            Id    = (int)reader["id"],
                            Nome  = (string)reader["nome"],
                            Ativo = (bool)reader["ativo"]
                        };
                    }
                }
            }

            return(ret);
        }
        public static LocalArmazenamentoModel RecuperarPeloId(int id)
        {
            LocalArmazenamentoModel ret = null;

            using (var db = new ContextoBD())
            {
                ret = db.LocaisArmazenamentos.Find(id);
            }
            return(ret);
        }
예제 #3
0
        public static LocalArmazenamentoModel RecuperarPeloId(int id)
        {
            LocalArmazenamentoModel ret = null;

            using (var conexao = new SqlConnection())
            {
                conexao.ConnectionString = ConfigurationManager.ConnectionStrings["principal"].ConnectionString;
                conexao.Open();

                var sql        = "select * from local_armazenamento where (id = @id)";
                var parametros = new { id };
                ret = conexao.Query <LocalArmazenamentoModel>(sql, parametros).SingleOrDefault();
            }

            return(ret);
        }
        public static bool ExcluirPeloId(int id)
        {
            var ret = false;

            if (RecuperarPeloId(id) != null)
            {
                using (var db = new ContextoBD())
                {
                    var localArmazenamento = new LocalArmazenamentoModel {
                        Id = id
                    };
                    db.LocaisArmazenamentos.Attach(localArmazenamento);
                    db.Entry(localArmazenamento).State = EntityState.Deleted;
                    db.SaveChanges();
                    ret = true;
                }
            }
            return(ret);
        }