Пример #1
0
    public static string WGrabarMunicipio(string sId, string sNombreMunic, string sRutMunic, string sNombreUserMunic, string sRutUserMunic, string sCorreoUserMunic,
                                          string sClave, string sClave2, string sTelefono, string sLogo)
    {
        JavaScriptSerializer scriptSerializer = new JavaScriptSerializer();
        List <string>        Lista            = new List <string>();
        Usuario usr = new Usuario();

        if (!UtilWeb.CheckSession(Lista, ref usr, HttpContext.Current))
        {
            return(scriptSerializer.Serialize(Lista.ToArray()));
        }

        try
        {
            if (sId.Trim().Length != 0)
            {
                if (sClave != sClave2)
                {
                    Lista.Add("CSD");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }

                if (sCorreoUserMunic == "")
                {
                    Lista.Add("CORREO_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }
                bool res = UtilWeb.IsValidMail(sCorreoUserMunic);
                if (!res)
                {
                    Lista.Add("CORREO_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }


                if (sRutMunic == "")
                {
                    Lista.Add("RUT_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }
                if (!UtilWeb.IsValidRut(sRutMunic))
                {
                    Lista.Add("RUT_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }

                if (sRutUserMunic == "")
                {
                    Lista.Add("RUT_USER_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }
                if (!UtilWeb.IsValidRut(sRutUserMunic))
                {
                    Lista.Add("RUT_USER_NO");
                    return(scriptSerializer.Serialize(Lista.ToArray()));
                }
            }

            ClienteMunicipio cliente = new ClienteMunicipio(usr);
            if (sId.Trim().Length == 0)
            {
                //cliente.Create(sNombreMunic, sRutMunic, sNombreUserMunic, sRutUserMunic, sCorreoUserMunic, sClave, sTelefono);
                sId = cliente.Create(sNombreMunic, sRutMunic, sNombreUserMunic, sRutUserMunic, sCorreoUserMunic, sClave, sTelefono).ToString();
            }
            else
            {
                cliente.Update(sId, sNombreMunic, sRutMunic, sNombreUserMunic, sRutUserMunic, sCorreoUserMunic, sClave, sTelefono);
            }


            if (sLogo.Trim().Length != 0 && !sLogo.Contains("image-placeholder.png"))
            {
                //data:image/png;base64,djsjsadkjadjkhadfkadkfakhdfkjhadkjh
                sLogo = sLogo.Substring(sLogo.IndexOf("base64,") + "base64,".Length);
                byte[] bytes = Convert.FromBase64String(sLogo);
                File.WriteAllBytes(string.Format(HttpContext.Current.Server.MapPath("~/images") + "\\MunLog_{0}.jpg", sId), bytes);
            }


            string html = "";
            WLeerUsuarioConectadoAndMunicipios_Internal(usr, ref html);

            Lista.Add("Exito");
            Lista.Add(html);
        }
        catch (Exception ex)
        {
            Lista.Add("Exception");
            Lista.Add(ex.Message);
            Lista.Add("Hubo un error no controlado en la aplicación, por favor inténtelo nuevamente, si el problema persiste contactarse con el administrador sistemas para revisar el log de eventos del servidor.");
        }
        return(scriptSerializer.Serialize(Lista.ToArray()));
    }