Example #1
0
        public static MvcHtmlString     BootstrapCheckBoxFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression)
        {
            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);
            string        labelText     = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            var           dataValue     = (bool)(metadata.Model ?? false);
            var           inputId       = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName);

            if (string.IsNullOrEmpty(labelText))
            {
                return(MvcHtmlString.Empty);
            }

            TagBuilder tag      = new TagBuilder("label");
            var        checkBox = new TagBuilder("input");

            checkBox.Attributes.Add("type", "checkbox");
            checkBox.Attributes.Add("name", inputId);
            checkBox.Attributes.Add("id", inputId);
            checkBox.Attributes.Add("data-val", "true");
            checkBox.Attributes.Add("value", "true");
            if (dataValue)
            {
                checkBox.Attributes.Add("checked", "checked");
            }
            var hidden = new TagBuilder("input");

            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("value", "false");
            hidden.Attributes.Add("name", inputId);

            tag.InnerHtml = checkBox.ToString(TagRenderMode.Normal) + Utilidades.CamelToTitleCase(labelText) + hidden.ToString(TagRenderMode.Normal);
            return(MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal)));
        }
Example #2
0
        public override void OnActionExecuting(ActionExecutingContext actionExecutingContext)
        {
            var usuario = SesionUsuario.Usuario;

            if (usuario == null)
            {
                actionExecutingContext.Controller.TempData["WarningMessage"] =
                    "Usted no posee permisos para visitar la aplicación ";
                var url = actionExecutingContext.HttpContext.Request.RawUrl;
                actionExecutingContext.Result =
                    new RedirectResult("/Account/LogOn?returnUrl=" + url);
                return;
            }
            if (!usuario.Activo || !usuario.Rol.Activo)
            {
                actionExecutingContext.Controller.TempData["WarningMessage"] =
                    "Usted no posee permisos para visitar la aplicación ";
                var url = actionExecutingContext.HttpContext.Request.RawUrl;
                actionExecutingContext.Result = new RedirectResult("/Account/LogOn?returnUrl=" + url);
                return;
            }
            var nombreControlador = actionExecutingContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            var nombreAccion      = actionExecutingContext.ActionDescriptor.ActionName;
            var permitir          = true;
            var accion            = _accionesRepository.ObtenerPorNombre(nombreAccion, nombreControlador);

            if (accion == null)
            {
                var controlador = _controladoresRepository.ObtenerPorNombre(nombreControlador);
                if (controlador == null)
                {
                    controlador = new Controlador()
                    {
                        Descripcion = nombreControlador + " creado automaticamente.",
                        Nombre      = nombreControlador,
                    };
                    _controladoresRepository.Guardar(controlador);
                }
                accion = new Accion()
                {
                    IdControlador   = controlador.Id,
                    Descripcion     = Utilidades.CamelToTitleCase(nombreAccion) + ", " + Utilidades.CamelToTitleCase(controlador.Nombre) + " creada automaticamente.",
                    NombreAmigable  = Utilidades.CamelToTitleCase(nombreAccion),
                    NombreAccion    = nombreAccion,
                    EsEtapa         = false,
                    ParaMenuLateral = false,
                    Orden           = 0
                };
                _accionesRepository.Guardar(accion);

                permitir = Utilidades.DebugMode();
            }
            else
            {
                permitir = Utilidades.DebugMode() || _permisosRolRepository.PoseePermiso(usuario.IdRol, accion.Id) ||
                           _permisosRolRepository.PoseePermisoSideBar(usuario.IdRol, accion.Id);
            }

            if (permitir)
            {
                SesionUsuario.CurrentNode =
                    SiteMap.Provider.FindSiteMapNode("/" + nombreControlador + "/" + nombreAccion);
                SesionUsuario.ParentNode = _menuRepository.ObtenerNodoPadre(SesionUsuario.CurrentNode);
                try
                {
                    GuardarLog(usuario.Id, accion.Id, actionExecutingContext.ActionParameters);
                }
                catch (Exception ex)
                {
                    XmlConfigurator.Configure();
                    Log.Error("Ha ocurrido un error al guardar el log en la base de datos. En la ruta " +
                              nombreControlador + "/" + nombreAccion + " error: " + ex.Message);
                }
                return;
            }
            actionExecutingContext.Controller.TempData["WarningMessage"] =
                "Usted no posee permisos para acceder a la ruta " + nombreControlador + "/" + nombreAccion;
            actionExecutingContext.Result = new RedirectResult("/Home/Desautorizado");
        }