예제 #1
0
        //
        // GET: /Perfil/Create
        public ActionResult Create()
        {
            List<Rol> sp = new List<Rol>();
            Session["selectedRoles"] = sp;

            //Declaraciones Generales para los request

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

            data = encoding.GetBytes("");

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

            return View(sp);
        }
예제 #2
0
        public ActionResult Create(string desc, int capacidad, int area, string email, int tipoCalle,
            string calle, string interior, int tipoUrb, string urb, string mzlt, string referencia, int tienda,
            int departamento = 0, int provincia = 0, int distrito = 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);

                Almacen p = new Almacen()
                {
                    IdAlmacen = 0,
                    Descripcion = desc,
                    Capacidad = capacidad,
                    Area = area,
                    IdDireccion = idDireccion,
                    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_Almacen(p));

                webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Almacen);
                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))
                {
                    Debug.WriteLine(Int32.Parse(u.Mensaje), "Almacen");
                    return RedirectToAction("Index");
                }

            }
            //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 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>));
            }

            ViewBag.Mensaje = u.Mensaje;
            return View();
        }
예제 #3
0
        public ActionResult Create(string nombre, int[] selectedPerfiles, bool estado = false, int tienda = 0)
        {
            //Declaraciones Generales para los request
            ASCIIEncoding encoding = new ASCIIEncoding();
            HttpWebRequest webrequest;
            HttpWebResponse webresponse;
            byte[] data;
            Stream newStream;
            ResponseBD u = new ResponseBD();

            //Select Perfiles
            List<Perfil> p = new List<Perfil>();
            encoding = new ASCIIEncoding();
            data = encoding.GetBytes("");

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

            //Obtener Perfiles seleccionados
            List<Perfil> sp = (List<Perfil>)Session["selectedPerfiles"];

            if (selectedPerfiles == null)
            {
                //Guardar Contraseña
                int idContrasena = 1;

                //Guardar Usuario
                Usuario usu = new Usuario()
                {
                    IdUsuario = 0,
                    Nombre = nombre,
                    IdContrasena = idContrasena,
                    Activo = estado,
                    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_Usuario(usu));

                Debug.WriteLine(JsonSerializer.add_Usuario(usu));

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

                if (u.Flujo.Equals(Constantes.OK))
                {
                    int idUsuario = Int32.Parse(u.Mensaje);

                    int i = 0;

                    foreach (var per in sp)
                    {
                        PerfilXUsuario pxu = new PerfilXUsuario()
                        {
                            IdUsuario = idUsuario,
                            IdPerfil = per.IdPerfil,
                            IdPerfilXUsuario = 0,
                            FechaAsignacion = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture)
                        };

                        data = encoding.GetBytes(JsonSerializer.add_PerfilXUsuario(pxu));

                        webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_PerfilXUsuario);
                        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("ERROR"))
                        {
                            ViewBag.Mensaje = u.Mensaje;
                            ViewBag.Productos = sp;
                            return View(p);
                        }

                        i++;
                    }

                    return RedirectToAction("Index");
                }

                //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>));
                }

                ViewBag.Mensaje = u.Mensaje;
                ViewBag.Perfiles = p;
                return View(sp);

            }

            foreach (var item in selectedPerfiles)
            {
                Perfil prd = new Perfil();

                data = encoding.GetBytes(JsonSerializer.selectById_Perfil(item));

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

                sp.Add(prd);

            }

            foreach (var i in sp)
            {
                p.RemoveAll(s => s.IdPerfil == i.IdPerfil);
            }

            ViewBag.Perfiles = p;

            Session["selectedPerfiles"] = sp;

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

            webrequest = (HttpWebRequest)WebRequest.Create(Constantes.SelectAll_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(sp);
        }
예제 #4
0
        public ActionResult Logout()
        {
            ResponseBD u = new ResponseBD();

            string token = (string)Session["token"];

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(JsonSerializer.logout_Usuario(token));

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

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

            HttpWebResponse 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));
            }

            return RedirectToAction("Login", "Usuario");
        }
예제 #5
0
        public ActionResult Login(string usuario, string contrasena, bool recordar = false)
        {
            ResponseBD u = new ResponseBD();

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(JsonSerializer.login_Usuario(usuario, contrasena));

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

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

            HttpWebResponse 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 timeout = recordar ? 525600 : 2; // Timeout in minutes,525600 = 365 days
                var ticket = new FormsAuthenticationTicket(usuario, recordar, timeout);
                string encrypted = FormsAuthentication.Encrypt(ticket);
                var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                cookie.Expires = System.DateTime.Now.AddMinutes(timeout);//My Line
                cookie.HttpOnly = true; // cookie not available in javascript.
                Response.Cookies.Add(cookie);

                Session["token"] = u.Mensaje;

                //Select Perfiles
                List<Perfil> p = new List<Perfil>();

                data = encoding.GetBytes(JsonSerializer.selectByUsuario_Sistema_Perfil(usuario));

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

                if (p.Count > 1)
                {
                    TempData["Perfiles"] = p;
                    return RedirectToAction("Select");
                }

                return RedirectToAction("Index", "Home");
            }
            else
            {
                ViewBag.Mensaje = u.Mensaje;
                return View();
            }
        }
예제 #6
0
        public ActionResult Create(string nombre, int[] selectedRoles, bool estado= false)
        {
            //Declaraciones Generales para los request
            ASCIIEncoding encoding = new ASCIIEncoding();
            HttpWebRequest webrequest;
            HttpWebResponse webresponse;
            byte[] data;
            Stream newStream;
            ResponseBD u = new ResponseBD();

            //Seleccciono Roles
            List<Rol> p = new List<Rol>();
            data = encoding.GetBytes("");

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

            //Obtener Roles seleccionados
            List<Rol> sp = (List<Rol>)Session["selectedRoles"];

            if (selectedRoles == null)
            {
                //Guardar Perfil
                Perfil per = new Perfil()
                {
                    IdPerfil = 0,
                    Nombre = nombre,
                    Activo = estado,
                    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_Perfil(per));

                webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Perfil);
                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 idPerfil = Int32.Parse(u.Mensaje);

                    //Agregar Productos seleccionados

                    int i = 0;

                    foreach (var rol in sp)
                    {
                        RolXPerfil rxp = new RolXPerfil()
                        {
                            IdRol = rol.IdRol,
                            IdPerfil = idPerfil,
                            IdRolXPerfil = 0,
                            FechaAsignacion = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture)
                        };

                        data = encoding.GetBytes(JsonSerializer.add_RolXPerfil(rxp));

                        webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_RolXPerfil);
                        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("ERROR"))
                        {
                            ViewBag.Mensaje = u.Mensaje;
                            ViewBag.Productos = sp;
                            return View(p);
                        }

                        i++;
                    }

                    return RedirectToAction("Index", "Usuario");
                }
                else
                {
                    ViewBag.Mensaje = u.Mensaje;
                    ViewBag.Perfiles = p;
                    return View(sp);
                }
            }

            foreach (var item in selectedRoles)
            {
                Rol rol = new Rol();

                data = encoding.GetBytes(JsonSerializer.selectById_Rol(item));

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

                sp.Add(rol);

            }

            foreach (var i in sp)
            {
                p.RemoveAll(s => s.IdRol == i.IdRol);
            }

            ViewBag.Roles = p;

            Session["selectedProducts"] = sp;

            return View(sp);
        }
예제 #7
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();
        }
예제 #8
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();
        }
예제 #9
0
        public ActionResult Create(string nombre, string desc, int unidad, int moneda, int presentacion, double precio,
            int tipo, string obs, HttpPostedFileBase file, bool perecible = false, bool estado = false)
        {
            //Declaraciones Generales para los request

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

            try
            {
                string imagen_url = "";
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(Server.MapPath("~/Images/barabares_img"), fileName);
                    file.SaveAs(path);
                    //var request = ControllerContext.RequestContext.HttpContext.Request;
                    string base_url = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
                    imagen_url = base_url + Constantes.URL_IMAGENES_BARABARES + fileName;
                }

                p = new Producto()
                {
                    IdProducto = 0,
                    Nombre = nombre,
                    Descripcion = desc,
                    IdUnidadProducto = unidad,
                    Presentacion = presentacion,
                    PrecioUnitario = precio,
                    Observaciones = obs,
                    Perecible = perecible,
                    Activo = estado,
                    IdTipoProducto = tipo,
                    IdMoneda = moneda,
                    FechaCreacion = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    Imagen = imagen_url
                };

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

                Debug.WriteLine(JsonSerializer.add_Producto(p));

                webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Producto);
                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 id = Int32.Parse(u.Mensaje);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                LogBarabares b = new LogBarabares()
                {
                    Accion = Constantes.LOG_CREAR,
                    Servicio = Constantes.Add_Producto,
                    Input = JsonSerializer.add_Producto(p),
                    Descripcion = ex.ToString(),
                    Clase = (p == null) ? "null" : p.GetType().Name,
                    Aplicacion = Constantes.ENTORNO_SISTEMA,
                    Estado = Constantes.ERROR,
                    Ip = "",
                    IdUsuario = 1 //TODO: obtener usuario de la sesión

                };

                data = encoding.GetBytes(JsonSerializer.add_LogBarabares(b));

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

                return RedirectToAction("Index");
            }

            //Select Unidad Producto
            data = encoding.GetBytes("");

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

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

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

            if (tipo == 1)
                ViewBag.Title = "Cerveza";
            else if (tipo == 2)
                ViewBag.Title = "Vino";
            else if (tipo == 3)
                ViewBag.Title = "Whisky";
            else if (tipo == 4)
                ViewBag.Title = "Vodka";
            else if (tipo == 5)
                ViewBag.Title = "Ron";
            else if (tipo == 6)
                ViewBag.Title = "Tequila";
            else if (tipo == 7)
                ViewBag.Title = "Pisco";
            else if (tipo == 8)
                ViewBag.Title = "Licores";
            else if (tipo == 9)
                ViewBag.Title = "Bebidas";
            else if (tipo == 10)
                ViewBag.Title = "Snacks";
            else if (tipo == 11)
                ViewBag.Title = "Cigarros";

            ViewBag.Tipo = tipo;

            ViewBag.Mensaje = u.Mensaje;
            return View();
        }
예제 #10
0
        public ActionResult Create(string nombrePromocion, string desc, string inicio, string fin, int moneda,
            string obs,int[] cantidad, int[] selectedProducts, int precio = 0, bool estadoPromocion = false, bool semana = false)
        {
            //Declaraciones Generales para los request

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

            //Select Producto
            List<Producto> sp = new List<Producto>();

            data = encoding.GetBytes("");

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

            //Obtener productos seleccionados

            List<Producto> p = (List<Producto>)Session["selectedProducts"];

            if (selectedProducts == null)
            {
                //Guardar promoción

                Promocion promo = new Promocion()
                {
                    IdPromocion = 0,
                    Nombre = nombrePromocion,
                    Descripcion = desc,
                    PrecioUnitario = precio,
                    //Observaciones = obs,
                    IdMoneda = moneda,
                    Semana = semana,
                    FechaInicio = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    FechaFin= DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    Imagen = "Imagen"
                };

                data = encoding.GetBytes(JsonSerializer.add_Promocion(promo));

                webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_Promocion);
                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 id = Int32.Parse(u.Mensaje);

                    //Agregar Productos seleccionados

                    int i = 0;

                    foreach (var prod in p)
                    {
                        DetallePromocion det = new DetallePromocion()
                        {
                            IdPromocion = id,
                            IdDetallePromocion = i + 1,
                            Cantidad = cantidad[i],
                            PrecioUnitario = prod.PrecioUnitario,
                            IdProducto = prod.IdProducto
                        };

                        data = encoding.GetBytes(JsonSerializer.add_DetallePromocion(det));

                        webrequest = (HttpWebRequest)WebRequest.Create(Constantes.Add_DetallePromocion);
                        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("ERROR"))
                        {
                            ViewBag.Mensaje = u.Mensaje;
                            ViewBag.Productos = sp;
                            return View(p);
                        }

                        i++;
                    }

                    return RedirectToAction("List");
                }
                else
                {
                    ViewBag.Mensaje = u.Mensaje;
                    ViewBag.Productos = sp;
                    return View(p);
                }
            }

            foreach (var item in selectedProducts)
            {
                Producto prd = new Producto();

                data = encoding.GetBytes(JsonSerializer.selectById_Producto(item));

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

                p.Add(prd);

            }

            foreach (var i in p)
            {
                sp.RemoveAll(s => s.IdProducto == i.IdProducto);
            }

            ViewBag.Productos = sp;

            Session["selectedProducts"] = p;

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

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

            return View(p);
        }