Exemplo n.º 1
0
        // GET: Acoes
        public ActionResult IndexAcao()
        {
            List <AcaoViewModel> listaAcoes = new List <AcaoViewModel>();

            try
            {
                List <ApplicationUser> listaUsrSist = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(u => u.Ativo == true).OrderBy(u => u.UserName).ToList();

                using (AppServiceAcoesUsuarios appServAcoesUsuarios = new AppServiceAcoesUsuarios(this.UfwCartNew, this.IdCtaAcessoSist))
                {
                    IEnumerable <Acao> listaTodasAcoes = appServAcoesUsuarios.UfwCartNew.Repositories.GenericRepository <Acao>().Get().OrderBy(a => a.DescricaoMedio).ToList();

                    AddListaAcao(appServAcoesUsuarios, listaUsrSist, listaTodasAcoes.Where(a => a.SeqAcesso == null).ToList(), listaAcoes);
                    AddListaAcao(appServAcoesUsuarios, listaUsrSist, listaTodasAcoes.Where(a => a.SeqAcesso != null).ToList(), listaAcoes);
                    //listAcessos = Mapper.Map<IEnumerable<DtoAcesso>, IEnumerable<ACESSOViewModel>>(null);
                }

                ViewBag.listaUsuarios = new SelectList(listaUsrSist, "Id", "Nome");
            }
            catch (Exception ex)
            {
                TypeInfo t = this.GetType().GetTypeInfo();
                IOFunctions.GerarLogErro(t, ex);
            }

            return(View(listaAcoes));
        }
Exemplo n.º 2
0
        public PartialViewResult MontarMenuUsuario(string IdUsuario)
        {
            ViewBag.CurrentControler = ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString().ToLower();
            ViewBag.CurrentAction    = ControllerContext.ParentActionViewContext.RouteData.Values["action"].ToString().ToLower();

            IEnumerable <DtoMenuAcaoList> Menu = new List <DtoMenuAcaoList>();
            ApplicationUser usrApp             = _userManager.FindById(IdUsuario);
            var             claims             = _userManager.GetClaims(IdUsuario).ToList();

            if (usrApp != null)
            {
                UsuarioIdentity usr = new UsuarioIdentity()
                {
                    Id = usrApp.Id,
                    IdCtaAcessoSist   = usrApp.IdCtaAcessoSist,
                    AccessFailedCount = usrApp.AccessFailedCount,
                    UserName          = usrApp.UserName,
                    Email             = usrApp.Email,
                    Nome                 = usrApp.Nome,
                    Ativo                = usrApp.Ativo,
                    CreateDate           = usrApp.CreateDate,
                    EmailConfirmed       = usrApp.EmailConfirmed,
                    LastLockoutDate      = usrApp.LastLockoutDate,
                    LastLoginDate        = usrApp.LastLoginDate,
                    LastPwdChangedDate   = usrApp.LastPwdChangedDate,
                    LockoutEnabled       = usrApp.LockoutEnabled,
                    PhoneNumber          = usrApp.PhoneNumber,
                    PhoneNumberConfirmed = usrApp.PhoneNumberConfirmed,
                    TwoFactorEnabled     = usrApp.TwoFactorEnabled
                };

                using (AppServiceAcoesUsuarios appService = new AppServiceAcoesUsuarios(this._ufwCartNew, this.IdCtaAcessoSist))
                {
                    Menu = appService.GetListMenuUsuario(usr, this.IdCtaAcessoSist);
                }
            }

            return(PartialView("_MenuUsuario", Menu));
        }
Exemplo n.º 3
0
        public JsonResult RemoveUsrAcao(long IdAcao, string IdUsuario)
        {
            bool   resposta = false;
            string msg      = string.Empty;

            try
            {
                using (AppServiceAcoesUsuarios appServiceAcoesUsuarios = new AppServiceAcoesUsuarios(this.UfwCartNew, this.IdCtaAcessoSist))
                {
                    var usrAcao = appServiceAcoesUsuarios.UfwCartNew.Repositories.GenericRepository <UsuarioAcao>().GetWhere(u => (u.IdAcao == IdAcao) && (u.IdUsuario == IdUsuario)).FirstOrDefault();

                    if ((usrAcao != null) || (!string.IsNullOrEmpty(usrAcao.IdUsuario)))
                    {
                        //fazer remove
                        var appResp = appServiceAcoesUsuarios.RemoveUsrAcao(IdAcao, IdUsuario);
                        resposta = appResp.Execute;
                        msg      = appResp.Message;
                    }
                    else
                    {
                        msg = string.Format("Ação {0} não encontrado para o usuário!", IdAcao);
                    }
                }
            }
            catch (Exception ex)
            {
                TypeInfo t = this.GetType().GetTypeInfo();
                IOFunctions.GerarLogErro(t, ex);
                msg = "Erro na solicitação: " + ex.Message;
            }
            var resultado = new
            {
                resposta = resposta,
                msg      = msg
            };

            return(Json(resultado));
        }
Exemplo n.º 4
0
        private void AddListaAcao(AppServiceAcoesUsuarios appServAcoesUsuarios, List <ApplicationUser> listaUsrSist, List <Acao> listaTodasAcoes, List <AcaoViewModel> listaAcoes)
        {
            bool addUser;

            try
            {
                foreach (var acao in listaTodasAcoes)
                {
                    List <UsuarioAcaoViewModel> listaUsrAcao = new List <UsuarioAcaoViewModel>();
                    var listaUsers = appServAcoesUsuarios.UfwCartNew.Repositories.GenericRepository <UsuarioAcao>().GetWhere(u => u.IdAcao == acao.Id).ToList();

                    foreach (var usuario in listaUsers)
                    {
                        addUser = true;
                        var usrtmp = listaUsrSist.Find(u => u.Id == usuario.IdUsuario);

                        if (acoesAdmin.Contains(acao.Id ?? 0))
                        {
                            addUser = usrtmp.Claims.Where(c => (c.ClaimType == ClaimTypes.Role) && (c.ClaimValue == "Admin")).Count() > 0;
                        }

                        if ((usrtmp != null) && addUser)
                        {
                            listaUsrAcao.Add(new UsuarioAcaoViewModel
                            {
                                IdUsuario = usuario.IdUsuario,
                                UserName  = usrtmp.UserName,
                                Email     = usrtmp.Email,
                                Nome      = usrtmp.Nome
                            });
                        }
                    }

                    listaAcoes.Add(new AcaoViewModel
                    {
                        Id = acao.Id,
                        IdCtaAcessoSist  = acao.IdCtaAcessoSist,
                        SeqAcesso        = acao.SeqAcesso,
                        Programa         = acao.Programa,
                        Obs              = acao.Obs,
                        DescricaoPequeno = acao.DescricaoPequeno,
                        DescricaoMedio   = acao.DescricaoMedio,
                        DescricaoGrande  = acao.DescricaoGrande,
                        DescricaoTip     = acao.DescricaoTip,
                        DescricaoBalao   = acao.DescricaoBalao,
                        Orientacao       = acao.Orientacao,
                        Action           = acao.Action,
                        Controller       = acao.Controller,
                        Parametros       = acao.Parametros,
                        IconeWeb         = acao.IconeWeb,
                        IconeMobile      = acao.IconeMobile,
                        Ativo            = acao.Ativo,
                        EmManutencao     = acao.EmManutencao,
                        ListaUsersAcao   = listaUsrAcao
                    });
                }
            }
            catch (Exception ex)
            {
                TypeInfo t = this.GetType().GetTypeInfo();
                IOFunctions.GerarLogErro(t, ex);
            }
        }
Exemplo n.º 5
0
        public JsonResult AddUsrAcao(long IdAcao, string IdUsuario)
        {
            bool   resposta = false;
            string msg      = string.Empty;
            string nome     = string.Empty;
            string usrName  = string.Empty;
            string email    = string.Empty;

            try
            {
                using (AppServiceAcoesUsuarios appServAcoesUsuarios = new AppServiceAcoesUsuarios(this.UfwCartNew, this.IdCtaAcessoSist))
                {
                    Acao acao = appServAcoesUsuarios.UfwCartNew.Repositories.GenericRepository <Acao>().GetWhere(a => a.Id == IdAcao).FirstOrDefault();

                    if ((acao != null) || (!string.IsNullOrEmpty(acao.Programa)))
                    {
                        var usuario = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(u => u.Id == IdUsuario).FirstOrDefault();

                        if ((usuario == null) || (!usuario.Ativo))
                        {
                            msg = "Usuário inexistente ou não ativo, não pode ser adicionado.";
                        }
                        else
                        {
                            if (acoesAdmin.Contains(acao.Id ?? 0))
                            {
                                if (!(usuario.Claims.Where(c => (c.ClaimType == ClaimTypes.Role) && (c.ClaimValue == "Admin")).Count() > 0))
                                {
                                    msg = "Esta permissão só pode ser atribuída para usuários do grupo Admin!";
                                }
                            }
                            else
                            {
                                //fazer add
                                var appResp = appServAcoesUsuarios.AddUsrAcao(IdAcao, IdUsuario);
                                resposta = appResp.Execute;
                                msg      = appResp.Message;
                                usrName  = usuario.UserName;
                                nome     = usuario.Nome;
                                email    = usuario.Email;
                            }
                        }
                    }
                    else
                    {
                        msg = string.Format("Ação {0} não encontrado!", IdAcao);
                    }
                }
            }
            catch (Exception ex)
            {
                TypeInfo t = this.GetType().GetTypeInfo();
                IOFunctions.GerarLogErro(t, ex);
                msg = "Erro na solicitação: " + ex.Message;
            }

            var resultado = new
            {
                resposta = resposta,
                msg      = msg,
                usuario  = new
                {
                    Id       = IdUsuario,
                    UserName = usrName,
                    Nome     = nome,
                    Email    = email
                }
            };

            return(Json(resultado));
        }