Beispiel #1
0
 public static string add_Persona(Persona p)
 {
     return "{" +
         '"' + "Activo" + '"' + ": " + (p.Activo ? "true" : "false") + ',' +
         '"' + "ApellidoMaterno" + '"' + ": " + '"' + p.ApellidoMaterno + '"' + ',' +
         '"' + "ApellidoPaterno" + '"' + ": " + '"' + p.ApellidoPaterno + '"' + ',' +
         '"' + "Celular" + '"' + ": " + p.Celular.ToString() + ',' +
         '"' + "Email" + '"' + ": " + '"' + p.Email + '"' + ',' +
         '"' + "FechaNacimiento" + '"' + ": " + '"' + Utils.dateToJson(p.FechaNacimiento) + '"' + ',' +
         '"' + "IdDireccion" + '"' + ": " + p.IdDireccion.ToString() + ',' +
         '"' + "IdPersona" + '"' + ": " + p.IdPersona.ToString() + ',' +
         '"' + "IdTipoDocumento" + '"' + ": " + p.IdTipoDocumento.ToString() + ',' +
         '"' + "IdTipoPersona" + '"' + ": " + p.IdTipoPersona.ToString() + ',' +
         '"' + "IdUsuario" + '"' + ": " + p.IdUsuario.ToString() + ',' +
         '"' + "Nombres" + '"' + ": " + '"' + p.Nombres + '"' + ',' +
         '"' + "NumeroDocumento" + '"' + ": " + p.NumeroDocumento.ToString() + ',' +
         '"' + "Sexo" + '"' + ": " + '"' + p.Sexo + '"' + ',' +
         '"' + "Telefono" + '"' + ": " + p.Telefono.ToString() +
         "}";
 }
Beispiel #2
0
        public ActionResult Create(string nombre, string appat, string apmat, string email, int tipoDoc,
            int nroDoc, string fechanac, int tipoCalle, string calle, string interior, int tipoUrb, int idTipo,
            string urb, string mzlt, string referencia, char sexo, int usuario, int departamento = 0, int provincia = 0,
            int distrito = 0, int telefono = 0, int celular = 0, int numero = 0, bool estado = false)
        {
            //Declaraciones Generales para los request

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

            Direccion d = new Direccion()
            {
                IdTipoCalle = tipoCalle,
                Calle = calle,
                Interior = interior,
                Numero = numero,
                IdTipoUrb = tipoUrb,
                Urbanizacion = urb,
                Mzlt = mzlt,
                Referencia = referencia,
                IdDepartamento = departamento,
                IdProvincia = provincia,
                IdDistrito = distrito,
                IdDireccion = 0
            };

            data = encoding.GetBytes(JsonSerializer.add_Direccion(d));

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Direccion);
            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))
            {
                int idDireccion = Int32.Parse(u.Mensaje);

                Persona p = new Persona()
                {
                    Nombres = nombre,
                    ApellidoPaterno = appat,
                    ApellidoMaterno = apmat,
                    Telefono = telefono,
                    Celular = celular,
                    Email = email,
                    IdTipoDocumento = tipoDoc,
                    NumeroDocumento = nroDoc,
                    FechaNacimiento = DateTime.Parse(fechanac),
                    Sexo = sexo,
                    IdTipoPersona = idTipo,
                    IdDireccion = idDireccion,
                    Activo = estado,
                    IdUsuario = usuario,
                    IdPersona = 0
                };

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

                webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Persona);
                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");
                }
            }

            //Select Tipo Documento
            data = encoding.GetBytes("");

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Combo_TipoDocumento);
            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.TipoDocumento = (List<TipoDocumento>)js.Deserialize(objText, typeof(List<TipoDocumento>));
            }

            //Select Tipo Calle
            data = encoding.GetBytes("");

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Combo_TipoCalle);
            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.TipoCalle = (List<TipoCalle>)js.Deserialize(objText, typeof(List<TipoCalle>));
            }

            //Select Tipo Urbanización
            data = encoding.GetBytes("");

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Combo_TipoUrb);
            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.TipoUrb = (List<TipoUrb>)js.Deserialize(objText, typeof(List<TipoUrb>));
            }

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

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Combo_Usuario);
            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.Usuario = (List<Usuario>)js.Deserialize(objText, typeof(List<Usuario>));
            }

            ViewBag.Title = "Empleados";
            ViewBag.Tipo = 2;
            ViewBag.Mensaje = u.Mensaje;
            return View();
        }