Beispiel #1
0
        /// <summary>
        /// esta classe precisa de um override de equals para poder usar o distinct
        /// igual o objeto acima, mas tipado, por performance
        /// </summary>
        /// <param name="ent">SegurancaActionViewModel a ser comparada</param>
        /// <returns>bool - True se forem iguais</returns>
        public virtual bool Equals(SegurancaActionViewModel ent)
        {
            if (ent == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this, ent))
            {
                return(true);
            }

            return(this.NomeAction.Equals(ent.NomeAction));
        }
        public JsonResult GetRoles(string completeActionName)
        {
            AcaoRepository acaoRep   = new AcaoRepository(db);
            Acao           existente = acaoRep.GetByName(completeActionName);

            if (existente == null)
            {
                existente      = new Acao();
                existente.Nome = completeActionName;

                try
                {
                    Type     tipo = typeof(TPAController);
                    Assembly asm  = Assembly.GetAssembly(tipo);
                    SegurancaActionViewModel action =
                        (
                            from t in asm.GetTypes().SelectMany(tp => tp.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public), (parent, child) => new { TipoController = parent, MetodoAction = child })
                            where tipo.IsAssignableFrom(t.TipoController) && ((t.TipoController.Name + "/" + t.MetodoAction.Name) == completeActionName)
                            orderby t.MetodoAction.Name
                            select new SegurancaActionViewModel
                    {
                        NomeAction = t.TipoController.Name + "/" + t.MetodoAction.Name,
                        Nome = ((t.MetodoAction.GetCustomAttribute(typeof(TPADescricaoAcaoControllerAttribute), false) as TPADescricaoAcaoControllerAttribute) ?? new TPADescricaoAcaoControllerAttribute(t.MetodoAction.Name, "")).Nome,
                        Descricao = ((t.MetodoAction.GetCustomAttribute(typeof(TPADescricaoAcaoControllerAttribute), false) as TPADescricaoAcaoControllerAttribute) ?? new TPADescricaoAcaoControllerAttribute("", t.TipoController.Name + "/" + t.MetodoAction.Name)).Descricao,
                    }
                        ).FirstOrDefault <SegurancaActionViewModel>();

                    if (action != null)
                    {
                        existente.NomeAmigavel      = action.Nome;
                        existente.DescricaoAmigavel = action.Descricao;
                    }
                }
                catch
                {
                }

                acaoRep.Save(existente);
            }

            if (existente.Perfis != null && existente.Perfis.Count > 0)
            {
                return(Json(existente.Perfis.Select(x => x.Id).ToArray <int>()));
            }
            else
            {
                return(Json(null));
            }
        }