コード例 #1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var porteEmpresaViewModel = _porteEmpresaAppService.ObterPorId(id.Value);

            if (porteEmpresaViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(porteEmpresaViewModel));
        }
コード例 #2
0
        private void ConexaoNativa(List <ClienteViewModel> clientes, string porteEmpresaId)
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"]
                                      .ConnectionString;
            string query = "SELECT ClienteId, Nome, PorteEmpresaId FROM dbo.Cliente WHERE PorteEmpresaId = " + porteEmpresaId;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        ClienteViewModel clienteViewModel = new ClienteViewModel();
                        clienteViewModel.ClienteId      = Guid.Parse(reader["ClienteId"].ToString());
                        clienteViewModel.Nome           = reader["Nome"].ToString();
                        clienteViewModel.PorteEmpresaId = Convert.ToInt32(reader["PorteEmpresaId"]);
                        clienteViewModel.PorteEmpresa   = _porteEmpresaAppService.ObterPorId(Convert.ToInt32(reader["PorteEmpresaId"]));
                        clientes.Add(clienteViewModel);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
        }