Exemplo n.º 1
0
        public ActionResult LoginAjax(string idusr, string passusr)
        {
            usrfile u = new usrfile();

            try
            {
                using (appbosaEntities ae = new appbosaEntities())
                {
                    string  pwd_encriptada = u.Encripta(passusr);
                    usrfile v = ae.usrfile.Where(a => a.idusr.Equals(idusr) && a.passusr.Equals(pwd_encriptada) && a.stateusr.Equals("V")).FirstOrDefault();
                    if (v != null)
                    {
                        List <rolespv> roles  = ae.rolespv.Where(a => a.idusr.Equals(idusr)).ToList();
                        List <string>  ciausr = ae.ciausrfile.Where(a => a.idusr.Equals(v.idusr)).Select(a => a.idcia).ToList();
                        var            cias   = ae.ciafile.Where(a => ciausr.Contains(a.idcia)).Select(a => new { a.idcia, a.descia }).ToList();
                        return(Json(new { respuesta = "EXITO: Verificaci\u00F3n exitosa", lista = roles, listacia = cias }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { respuesta = "ERROR: Credenciales inv\u00E1lidas" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (System.Data.EntityException ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
            catch (Exception ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
        }
Exemplo n.º 2
0
        public JsonResult SendEmail(string email, string tipdoc, string serie, string correlativo, string fecha, string importe)
        {
            try
            {
                appbosaEntities db              = new appbosaEntities();
                setupmail       stmail          = db.setupmail.ToList().First();
                usrfile         u               = new usrfile();
                string          FromEmail       = stmail.DIRMAIL;
                string          FromDisplayName = stmail.NOMMAIL;
                string          FromPassword    = u.Desencripta(stmail.PASSMAIL);
                string          subject         = "Documento Electrónico";
                string          body            = "";
                string          host            = stmail.SMTPMAIL;
                int             port            = int.Parse(stmail.PUERTO_SMTP);
                string          SslAct          = stmail.CONEXION_SSL;

                var fromAddress = new MailAddress(FromEmail, FromDisplayName);
                var toAddress   = new MailAddress(email);
                var smtp        = new SmtpClient
                {
                    Host                  = host,
                    Port                  = port,
                    EnableSsl             = SslAct.Equals("S"),
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, FromPassword)
                };

                var root = Server.MapPath("~/PDF/");
                if (!System.IO.Directory.Exists(@root))
                {
                    System.IO.Directory.CreateDirectory(@root);
                }
                var pdfname = String.Format("{0} - {1}.pdf", "Documento Electrónico", DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss"));
                var path    = Path.Combine(root, pdfname);
                path = Path.GetFullPath(path);
                var something = new Rotativa.ActionAsPdf("Respuesta", new { tipdoc = tipdoc, serie = serie, correlativo = correlativo, fecha = fecha, importe = importe })
                {
                    FileName = pdfname,
                };
                var binary = something.BuildPdf(this.ControllerContext);
                System.IO.File.Create(path).Close();
                System.IO.File.WriteAllBytes(@path, binary);

                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject, Body = body
                })
                {
                    message.Attachments.Add(new Attachment(path));
                    smtp.Send(message);
                }
                System.IO.File.Delete(@path);
                return(Json(new { respuesta = "EXITO: Email enviado a " + email }, JsonRequestBehavior.AllowGet));
            }
            catch (System.Data.EntityException ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
            catch (Exception ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
        }
Exemplo n.º 3
0
 public ActionResult Login(string idusr, string passusr, string rol, string idcia, string sucur)
 {
     if (String.IsNullOrWhiteSpace(idusr))
     {
         return(Json(new { respuesta = "ERROR: El usuario no puede ser nulo o vac\u00EDo" }, JsonRequestBehavior.AllowGet));
     }
     if (String.IsNullOrWhiteSpace(passusr))
     {
         return(Json(new { respuesta = "ERROR: La contraseña no puede ser nulo o vac\u00EDo" }, JsonRequestBehavior.AllowGet));
     }
     if (String.IsNullOrWhiteSpace(idcia))
     {
         return(Json(new { respuesta = "ERROR: El c\u00F3digo de cia no puede ser nulo o vac\u00EDo" }, JsonRequestBehavior.AllowGet));
     }
     if (String.IsNullOrWhiteSpace(sucur))
     {
         return(Json(new { respuesta = "ERROR: La sucursal no puede ser nulo o vac\u00EDo" }, JsonRequestBehavior.AllowGet));
     }
     if (String.IsNullOrWhiteSpace(rol))
     {
         return(Json(new { respuesta = "ERROR: El rol no puede ser nulo o vac\u00EDo" }, JsonRequestBehavior.AllowGet));
     }
     try
     {
         usrfile u = new usrfile();
         u.idusr = idusr; u.passusr = passusr;
         using (appbosaEntities ae = new appbosaEntities())
         {
             string  pwd_encriptada = u.Encripta(u.passusr);
             usrfile v = ae.usrfile.Where(a => a.idusr.Equals(u.idusr) && a.passusr.Equals(pwd_encriptada) && a.stateusr.Equals("V")).FirstOrDefault();
             if (v != null)
             {
                 Session["Loged_usrfile_idusr"]    = v.idusr;
                 Session["Loged_usrfile_typeusr"]  = v.typeusr;
                 Session["Loged_usrfile_ciafile"]  = idcia;
                 Session["Loged_usrfile_sucursal"] = sucur;
                 Session["Loged_usrfile_rol"]      = rol;
                 Session["Loged_usrfile_desusr"]   = v.desusr;
                 punemi punemi = ae.punemi.Where(a => a.codcia.Equals(idcia) && a.sucursal.Equals(sucur) && a.situa.Equals("V")).FirstOrDefault();
                 if (punemi != null)
                 {
                     Session["Loged_usrfile_punemi"] = punemi.codigo;
                 }
                 string redir = "/UndAtencion/Index";//RedireccionTiposUuario();
                 return(Json(new { respuesta = redir }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { respuesta = "ERROR: Credenciales inv\u00E1lidas" }, JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (System.Data.EntityException ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
     catch (Exception ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
 }
Exemplo n.º 4
0
        public JsonResult Aperturar(string codigo, string idperatencion, string divate, string pwd)
        {
            try
            {
                string codcia = Session["Loged_usrfile_ciafile"].ToString();
                parreg pr     = db.parreg.Where(a => a.IDCIA.Equals(codcia) && a.FORM.Equals("POS")).FirstOrDefault();
                if (pr.POS_IS_CLAVE_PERATENCION.Equals("S"))
                {
                    usrfile     u      = new usrfile();
                    string      newpwd = u.Encripta(pwd);
                    peratencion p      = db.peratencion.Where(a => a.codcia.Equals(codcia) && a.situa.Equals("V") && a.codigo.Equals(idperatencion)).FirstOrDefault();
                    if (p == null || !p.clave.Equals(newpwd))
                    {
                        return(Json(new { respuesta = Msg.PwdIncorrecta }, JsonRequestBehavior.AllowGet));
                    }
                }
                var rol = Session["Loged_usrfile_rol"];
                if ("C".Equals(rol) || "M".Equals(rol))
                {
                    string      sucursal  = Session["Loged_usrfile_sucursal"].ToString();
                    string      codpunemi = Session["Loged_usrfile_punemi"].ToString();
                    string      idusr     = Session["Loged_usrfile_idusr"].ToString();
                    peratencion per       = db.peratencion.Where(a => a.codcia.Equals(codcia) && a.codigo.Equals(idperatencion) && a.situa.Equals("V")).FirstOrDefault();
                    if (per == null)
                    {
                        return(Json(new { respuesta = "ERROR: El c\u00F3digo del personal de atenci\u00F3n no existe" }, JsonRequestBehavior.AllowGet));
                    }
                    undatencion undatencion = db.undatencion.Where(a => a.CODCIA.Equals(codcia) && a.SUCURSAL.Equals(sucursal) &&
                                                                   a.CODIGO.Equals(codigo) && a.DIVATENCION.Equals(divate) && a.ESTADO.Equals("V")).FirstOrDefault();
                    if (undatencion == null)
                    {
                        return(Json(new { respuesta = "ERROR: La unidad de atenci\u00F3n no existe" }, JsonRequestBehavior.AllowGet));
                    }

                    conc cc = db.conc.Where(a => a.CODCIA.Equals(codcia) && a.SUCURSAL.Equals(sucursal) && a.UNDATENCION.Equals(undatencion.CODIGO) &&
                                            a.SITUACION.Equals("A")).FirstOrDefault();
                    if (cc != null)
                    {
                        return(Json(new { respuesta = "EXITO: La unidad de atenci\u00F3n est\u00E1 aperturada", div = undatencion.DIVATENCION, und = undatencion.CODIGO, per = per.codigo, rol = rol }, JsonRequestBehavior.AllowGet));
                    }

                    int?tmp = this.generar(codcia);
                    if (tmp == null)
                    {
                        return(Json(new { respuesta = "ERROR: Error al generar el c\u00F3digo del consumo" }, JsonRequestBehavior.AllowGet));
                    }
                    conc conc = new conc();
                    conc.CODCIA      = codcia;
                    conc.CODIGO      = tmp.ToString().PadLeft(10, '0');
                    conc.SUCURSAL    = sucursal;
                    conc.UNDATENCION = undatencion.CODIGO;
                    conc.PERATENCION = per.codigo;
                    conc.FECHA       = DateTime.Now.Date;
                    conc.HORA        = DateTime.Now.ToString("hh:mm:ss");
                    conc.USER        = idusr;
                    conc.SITUACION   = "A";
                    conc.FACTURANDO  = "N";
                    db.conc.Add(conc);
                    db.SaveChanges();
                    return(Json(new { respuesta = "EXITO: Unidad de atenci\u00F3n aperturada", div = undatencion.DIVATENCION, und = undatencion.CODIGO, per = per.codigo, rol = rol }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { respuesta = "ERROR: Ud. no tiene los permisos para realizar la operaci\u00F3n" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (System.Data.EntityException ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
            catch (Exception ex) { return(Json(new { respuesta = "ERROR: " + ex.Message }, JsonRequestBehavior.AllowGet)); }
        }