Exemple #1
0
        public List <mSucursal> ListaSucursalesBanco(int idBanco)
        {
            List <mSucursal> objLista = null;
            SqlConnection    Conn     = ConexionSQL();

            using (Conn)
            {
                try
                {
                    Conn.Open();
                    SqlCommand command = new SqlCommand()
                    {
                        CommandType = CommandType.StoredProcedure,
                        CommandText = "PA_MANT_SUCURSAL",
                        Connection  = Conn
                    };
                    command.Parameters.Add("@PINT_ID_BANCO", SqlDbType.Int).Value      = idBanco;
                    command.Parameters.Add("@PVCH_ACCION", SqlDbType.VarChar, 3).Value = "SEB";
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    if (reader != null)
                    {
                        mSucursal modelo = null;
                        objLista = new List <mSucursal>();
                        int posIdsucursal     = reader.GetOrdinal("ID_SUCURSAL");
                        int posNombreSucursal = reader.GetOrdinal("NOM_SUCURSAL");
                        int posDireccion      = reader.GetOrdinal("DIRECCION");

                        while (reader.Read())
                        {
                            modelo                = new mSucursal();
                            modelo.idSucursal     = reader.GetInt32(posIdsucursal);
                            modelo.NombreSucursal = reader.GetString(posNombreSucursal);
                            modelo.Direccion      = reader.GetString(posDireccion);
                            objLista.Add(modelo);
                        }
                    }

                    reader.Close();
                    reader.Dispose();
                    command.Dispose();
                }
                catch (SqlException Ex)
                {
                }
                finally
                {
                    if (Conn.State == ConnectionState.Open)
                    {
                        Conn.Close();
                        Conn.Dispose();
                    }
                }
                return(objLista);
            }
        }
        public JsonResult MantSucursal(string sAccion, mSucursal modelo)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:55947");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            string     sUri     = string.Format("/api/Sucursal/MantSucursal?sAccion={0}", sAccion);
            var        response = client.PostAsJsonAsync(sUri, modelo).Result;
            mResultado obj      = null;

            if (response.IsSuccessStatusCode)
            {
                JavaScriptSerializer ser = new JavaScriptSerializer();
                obj = ser.Deserialize <mResultado>(response.Content.ReadAsStringAsync().Result);
            }

            return(Json(new { resultado = obj.resultado, mensaje = obj.mensaje }, JsonRequestBehavior.AllowGet));
        }