Exemplo n.º 1
0
 public static string add_Vehiculo(Vehiculo d)
 {
     return "{" +
         '"' + "IdVehiculo" + '"' + ": " + d.IdVehiculo.ToString() + ',' +
         '"' + "Placa" + '"' + ": " + '"' + d.Placa + '"' + ',' +
         '"' + "Descripcion" + '"' + ": " + '"' + d.Descripcion + '"' + ',' +
         '"' + "Capacidad" + '"' + ": " + d.Capacidad.ToString() + ',' +
         '"' + "Marca" + '"' + ": " + d.Marca.ToString() + ',' +
         '"' + "Modelo" + '"' + ": " + d.Modelo.ToString() + ',' +
         '"' + "Activo" + '"' + ": " + (d.Activo ? "true" : "false") + ',' +
         '"' + "FechaCreacion" + '"' + ": " + '"' + Utils.dateToJson(d.FechaCreacion) + '"' + ',' +
         '"' + "IdTienda" + '"' + ": " + d.IdTienda.ToString() +
         "}";
 }
Exemplo n.º 2
0
        public ActionResult Create(string placa, string desc, int capacidad, int marca, int modelo,
            int tienda, bool estado = false)
        {
            //Declaraciones Generales para los request

            ASCIIEncoding encoding = new ASCIIEncoding();
            HttpWebRequest webrequest;
            HttpWebResponse webresponse;
            byte[] data;
            Stream newStream;
            ResponseBD u = new ResponseBD();

            Vehiculo p = new Vehiculo()
            {
                IdVehiculo = 0,
                Placa = placa,
                Descripcion = desc,
                Capacidad = capacidad,
                Marca = marca,
                Modelo = modelo,
                Activo = estado,
                IdTienda = tienda,
                FechaCreacion = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                UltimaModificacion = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
            };

            data = encoding.GetBytes(JsonSerializer.add_Vehiculo(p));

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Vehiculo);
            webrequest.Method = Constantes.PostMethod;
            webrequest.ContentType = Constantes.ContentType;
            webrequest.ContentLength = data.Length;

            newStream = webrequest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            webresponse = (HttpWebResponse)webrequest.GetResponse();

            using (var reader = new StreamReader(webresponse.GetResponseStream()))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                var objText = reader.ReadToEnd();
                u = (ResponseBD)js.Deserialize(objText, typeof(ResponseBD));
            }

            if (u.Flujo.Equals(Constantes.OK))
            {
                return RedirectToAction("Index","Almacen");
            }

            //Select Tienda
            data = encoding.GetBytes("");

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Combo_Tienda);
            webrequest.Method = Constantes.PostMethod;
            webrequest.ContentType = Constantes.ContentType;
            webrequest.ContentLength = data.Length;

            newStream = webrequest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            webresponse = (HttpWebResponse)webrequest.GetResponse();

            using (var reader = new StreamReader(webresponse.GetResponseStream()))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                var objText = reader.ReadToEnd();
                ViewBag.Tienda = (List<Tienda>)js.Deserialize(objText, typeof(List<Tienda>));
            }

            return View();
        }