public async Task <ActionResult> ExportaRelEnquetesCadastradasPorSexo(int enqueteId)
        {
            var _pergunta = await this.srvEnquete.RetornarEnquetePorId(enqueteId);

            var _respostas = await this.srvResposta.RetornarTodosRespostas();

            var _toList = _respostas.Where(r => r.PerguntaId == _pergunta.PerguntaId).ToList();

            var _respostaJsonToList = new List <RelRespostasPorSexo>();

            foreach (var resposta in _toList)
            {
                var _respostasRespondidas = await this.srvPerguntaResposta.RetornarPerguntaRespostaPorResposta(resposta.Id);

                _respostaJsonToList.Add(new RelRespostasPorSexo
                {
                    Id            = resposta.Id,
                    TextoResposta = resposta.TextoResposta,
                    PorHomens     = resposta.PerguntaResposta.Count(r => r.Usuario.Sexo.HasValue && r.Usuario.Sexo.Value == EnumSexo.Masculino),
                    PorMulheres   = resposta.PerguntaResposta.Count(r => r.Usuario.Sexo.HasValue && r.Usuario.Sexo.Value == EnumSexo.Feminino)
                });
            }

            var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelRespostasPorSexo>(_respostaJsonToList);

            return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Respostas_Enquete_PorSexo_{0}.xls", DateTime.Now.ToShortDateString())));
        }
        public async Task <ActionResult> ExportarRespostasEnquete(int enqueteId)
        {
            var _pergunta = await this.srvEnquete.RetornarEnquetePorId(enqueteId);

            var _respostas = await this.srvResposta.RetornarTodosRespostas();

            var _toList = _respostas.Where(r => r.PerguntaId == _pergunta.PerguntaId).ToList();

            List <RelEnquetesRespostas> _mapper = new List <RelEnquetesRespostas>();

            foreach (var resposta in _toList)
            {
                var _respostasRespondidas = await this.srvPerguntaResposta.RetornarPerguntaRespostaPorPergunta(resposta.Id);

                var percent = (_respostasRespondidas != null && !_respostasRespondidas.Any() && _respostasRespondidas.Count > 0)
                    ? _respostasRespondidas.First().percentual
                    : 0;

                _mapper.Add(new RelEnquetesRespostas
                {
                    Id             = resposta.Id,
                    TextoRespostas = resposta.TextoResposta,
                    Percentual     = percent.ToString(),
                    Categoria      = _pergunta.EnqueteCategoria != null && _pergunta.EnqueteCategoria.Any() ? _pergunta.EnqueteCategoria.First().Categoria.Nome : "Sem Categoria",
                    TextoPergunta  = _pergunta.Pergunta.TextoPergunta
                });
            }

            var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelEnquetesRespostas>(_mapper);

            return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Respostas_Enquete_{0}.xls", DateTime.Now.ToShortDateString())));
        }
        public async Task <ActionResult> ExportarEmpresasCadastrados()
        {
            var _empresas = await this.srvEmpresa.RetornarTodasEmpresas();

            var _toList = _empresas.ToList();
            var mapper  = _toList.Select(x => new RelEmpresaViewModel
            {
                Nome        = x.Nome,
                Documento   = x.Documento.Numero.ToString(),
                DataCriacao = x.DataCriacao.ToShortDateString(),
                QtdePush    = x.QtdePush.ToString()
            });

            var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelEmpresaViewModel>(mapper.ToList());

            return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Cadastro_Empresa_{0}.xls", DateTime.Now.ToShortDateString())));
        }
        public async Task <ActionResult> ExportarEnquetesCadastradas()
        {
            if (UsuarioLogado.UsuarioAutenticado().Perfil == Domain.Enumeradores.EnumPerfil.AdministradorMaster)
            {
                var _enquetes = await this.srvEnquete.RetornarTodasEnquetes();

                var _toList = _enquetes.Where(e => e.Tipo == EnumTipoEnquete.Interesse || e.Tipo == EnumTipoEnquete.Publica).OrderByDescending(e => e.DataCriacao).ToList();
                var mapper  = _toList.Select(x => new RelEnquetesViewModel
                {
                    Id            = x.Id,
                    Categoria     = x.EnqueteCategoria != null && x.EnqueteCategoria.Any() ? x.EnqueteCategoria.First().Categoria.Nome : "Sem categoria",
                    Imagem        = String.IsNullOrEmpty(x.Imagem) ? "Sem Imagem" : x.Imagem,
                    Status        = x.Status.GetDescription(),
                    TemVoucher    = x.TemVoucher ? "Sim" : "Não",
                    TextoPergunta = x.Pergunta.TextoPergunta,
                    UrlVideo      = String.IsNullOrEmpty(x.UrlVideo) ? "Sem vídeo" : x.UrlVideo,
                    DataCriacao   = x.DataCriacao.ToShortDateString(),
                });

                var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelEnquetesViewModel>(mapper.ToList());
                return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Cadastro_Enquete_{0}.xls", DateTime.Now.ToShortDateString())));
            }
            else
            {
                var _enquetes = await this.srvEnquete.RetornarTodasEnquetes();

                var _toList = _enquetes.Where(x => x.EmpresaId == UsuarioLogado.UsuarioAutenticado().EmpresaId).OrderByDescending(x => x.DataCriacao).ToList();
                var mapper  = _toList.Select(x => new RelEnquetesViewModel
                {
                    Id            = x.Id,
                    Categoria     = x.EnqueteCategoria != null && x.EnqueteCategoria.Any() ? x.EnqueteCategoria.First().Categoria.Nome : "Sem categoria",
                    Imagem        = String.IsNullOrEmpty(x.Imagem) ? "Sem Imagem" : x.Imagem,
                    Status        = x.Status.GetDescription(),
                    TemVoucher    = x.TemVoucher ? "Sim" : "Não",
                    TextoPergunta = x.Pergunta.TextoPergunta,
                    UrlVideo      = String.IsNullOrEmpty(x.UrlVideo) ? "Sem vídeo" : x.UrlVideo,
                    DataCriacao   = x.DataCriacao.ToShortDateString(),
                });

                var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelEnquetesViewModel>(mapper.ToList());
                return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Cadastro_Enquete_{0}.xls", DateTime.Now.ToShortDateString())));
            }
        }
        public async Task <ActionResult> ExportaRelEnquetesCadastradasPorIdade(int enqueteId)
        {
            var _pergunta = await this.srvEnquete.RetornarEnquetePorId(enqueteId);

            var _respostas = await this.srvResposta.RetornarTodosRespostas();

            var _toList = _respostas.Where(r => r.PerguntaId == _pergunta.PerguntaId).ToList();

            var _respostaJsonToList = new List <RelRespostasPorIdade>();

            foreach (var resposta in _toList)
            {
                var _respostasRespondidas = await this.srvPerguntaResposta.RetornarPerguntaRespostaPorResposta(resposta.Id);

                var groupNascimento = (from n in _respostasRespondidas.Where(c => c.Usuario.DataNascimento.HasValue)
                                       group n by n.Usuario.DataNascimento.Value.Year into porAnoNascimento
                                       select new
                {
                    AnoNascimento = DateTime.Now.Year - porAnoNascimento.Key,
                    QtdeRespostas = porAnoNascimento.Count()
                }).ToList();

                foreach (var nascimento in groupNascimento)
                {
                    _respostaJsonToList.Add(new RelRespostasPorIdade
                    {
                        Id            = resposta.Id,
                        TextoResposta = resposta.TextoResposta,
                        Idade         = nascimento.AnoNascimento
                    });
                }
            }

            var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelRespostasPorIdade>(_respostaJsonToList);

            return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Respostas_Enquete_PorIdade_{0}.xls", DateTime.Now.ToShortDateString())));
        }
        public async Task <ActionResult> ExportaRelEnquetesCadastradasPorMunicipio(int enqueteId)
        {
            var _pergunta = await this.srvEnquete.RetornarEnquetePorId(enqueteId);

            var _respostas = await this.srvResposta.RetornarTodosRespostas();

            var _toList = _respostas.Where(r => r.PerguntaId == _pergunta.PerguntaId).ToList();

            var _respostaJsonToList = new List <RelRespostasPorMunicipio>();

            foreach (var resposta in _toList)
            {
                var _respostasRespondidas = await this.srvPerguntaResposta.RetornarPerguntaRespostaPorResposta(resposta.Id);

                var groupMunicipio = (from mun in _respostasRespondidas.Where(c => !String.IsNullOrEmpty(c.Usuario.Municipio))
                                      group mun by mun.Usuario.Municipio into porMunicipio
                                      select new
                {
                    Municipio = porMunicipio.Key,
                    QtdeRespostas = porMunicipio.Count()
                }).ToList();

                foreach (var municipio in groupMunicipio)
                {
                    _respostaJsonToList.Add(new RelRespostasPorMunicipio
                    {
                        Id            = resposta.Id,
                        TextoResposta = resposta.TextoResposta,
                        Municipio     = municipio.Municipio
                    });
                }
            }

            var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelRespostasPorMunicipio>(_respostaJsonToList);

            return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Respostas_Enquete_PorMunicipio_{0}.xls", DateTime.Now.ToShortDateString())));
        }
        public async Task <ActionResult> ExportarUsuariosCadastrados()
        {
            if (UsuarioLogado.UsuarioAutenticado().Perfil == Domain.Enumeradores.EnumPerfil.AdministradorMaster)
            {
                var _usuarios = await this.srvUsuario.RetornarTodosUsuarios();

                var _toList = _usuarios.OrderBy(x => x.Nome).ToList();

                var listaUsuarios = new List <Usuario>();

                foreach (var usuarios in _toList)
                {
                    foreach (var usuario in _usuarios)
                    {
                        if (!listaUsuarios.Any(x => x.Email == usuario.Email))
                        {
                            listaUsuarios.Add(usuario);
                        }
                    }
                }


                var mapper = listaUsuarios.Select(x => new RelUsuariosViewModel
                {
                    Nome           = String.IsNullOrEmpty(x.Nome) ? "Não Informado" : x.Nome,
                    Email          = String.IsNullOrEmpty(x.Email) ? "Não Informado" : x.Email,
                    Telefone       = String.IsNullOrEmpty(x.Telefone) ? "Não Informado" : x.Telefone,
                    DataCriacao    = x.DataCriacao.ToShortDateString(),
                    DataNascimento = x.DataNascimento == null ? "Não Informado" : x.DataNascimento.Value.ToShortDateString(),
                    Municipio      = String.IsNullOrEmpty(x.Municipio) ? "Não Informado" : x.Municipio,
                    Sexo           = x.Sexo == null ? "Não Informado" : x.Sexo.GetDescription()
                });

                var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelUsuariosViewModel>(mapper.ToList());
                return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Cadastro_Usuarios_{0}.xls", DateTime.Now.ToShortDateString())));
            }
            else
            {
                var _usuarios = await this.srvUsuario.RetornarTodosUsuarios();

                var _toList = _usuarios.Where(e => e.EmpresaId == UsuarioLogado.UsuarioAutenticado().EmpresaId).OrderBy(x => x.Nome).ToList();

                var listaUsuarios = new List <Usuario>();

                foreach (var usuarios in _toList)
                {
                    foreach (var usuario in _usuarios)
                    {
                        if (!listaUsuarios.Any(x => x.Email == usuario.Email))
                        {
                            listaUsuarios.Add(usuario);
                        }
                    }
                }

                var mapper = listaUsuarios.Select(x => new RelUsuariosViewModel
                {
                    Nome           = String.IsNullOrEmpty(x.Nome) ? "Não Informado" : x.Nome,
                    Email          = String.IsNullOrEmpty(x.Email) ? "Não Informado" : x.Email,
                    Telefone       = String.IsNullOrEmpty(x.Telefone) ? "Não Informado" : x.Telefone,
                    DataCriacao    = x.DataCriacao.ToShortDateString(),
                    DataNascimento = x.DataNascimento == null ? "Não Informado" : x.DataNascimento.Value.ToShortDateString(),
                });

                var _arqExcelBytes = new SimpleExcelExport.ExportToExcel().ListToExcel <RelUsuariosViewModel>(mapper.ToList());
                return(File(_arqExcelBytes, "application/ms-excel", string.Format("Relatorio_Cadastro_Usuarios_{0}.xls", DateTime.Now.ToShortDateString())));
            }
        }