Example #1
0
 public ActionResult RegistrarNumeros(SorteioViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (sorteioService = new SorteioService())
             {
                 using (UsuarioService = new UsuarioService(sorteioService.Repository.RepositoryFactory))
                 {
                     model.Sorteio.DataSorteio = DateTime.Now;
                     model.Sorteio.Usuarios    = UsuarioService.Repository.RecuperarPorId((Session["User"] as Usuarios).Id);
                     sorteioService.InserirSorteio(model.Sorteio);
                 }
             }
         }
     }
     catch (AggregateException ex)
     {
         TempData["Erro"] = ex.InnerExceptions.Select(x => x.Message);
     }
     catch (Exception ex)
     {
         TempData["Erro"] = ex.Message;
     }
     InicializarModel(model);
     return(View("Cadastrar", model));
 }
Example #2
0
 private void InicializarModel(SorteioViewModel model)
 {
     using (UsuarioService = new UsuarioService())
     {
         using (sorteioService = new SorteioService(UsuarioService.Repository.RepositoryFactory))
         {
             model.Usuario  = UsuarioService.Repository.RecuperarPorId((Session["User"] as Usuarios).Id);
             model.Sorteios = sorteioService.Repository.RecuperarPorAno(DateTime.Now.Year).ToList();
         }
     }
 }
        public ActionResult Sortear()
        {
            var objJogo = JogoFactory.Criar(TipoJogo.MegaSena);

            var viewModel = new SorteioViewModel
            {
                NumerosSorteados       = objJogo.Sortear(),
                ListaApostasGanhadoras = objJogo.ApurarGanhadores(this.ListaApostas)
            };

            return(View("~/Views/Loteria/Sorteio.cshtml", viewModel));
        }
        public ActionResult Filtrar()
        {
            SorteioViewModel model = new SorteioViewModel();

            try
            {
                model.Materias = new MateriaService().Listar();
            }
            catch (Exception ex)
            {
            }
            return(View(model));
        }
        public ActionResult Sortear(SorteioViewModel model)
        {
            Guid Identificador = new Guid();

            try
            {
                CartaService service = new CartaService();
                Identificador = service.GerarSorteio(model.MateriasIDs, model.Favoritas);
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("Detalhe", "FlashCard", new { id = Identificador }));
        }
Example #6
0
 public async Task AtualizarSorteio(SorteioViewModel sorteioAtual)
 {
     await Clients.All.SendAsync("atualizarSorteio", sorteioAtual);
 }
Example #7
0
        public ActionResult Drawlots(int idSorteio)
        {
            var responseParticipantes = _sorteioAppService.GetById(idSorteio);

            if (!responseParticipantes.IsSuccessStatusCode)
            {
                return(ErrorMessage("Erro ao trazer participantes"));
            }


            var dadosParticipantesSorteio = JsonConvert.DeserializeObject <SorteioViewModel>
                                                (responseParticipantes.Content.ReadAsStringAsync().Result);

            if (!dadosParticipantesSorteio.SorteioParticipantes.Any())
            {
                return(ErrorMessage("Não foi encontrado nenhum participante"));
            }

            if (dadosParticipantesSorteio.QtdParticipantes <= dadosParticipantesSorteio.QtdeItens)
            {
                foreach (var vencedor in dadosParticipantesSorteio.SorteioParticipantes)
                {
                    _sorteioParticipanteAppService.VencedorParticipantesSorteio(idSorteio, vencedor.Id_Participante);

                    var sorteado      = _usuarioAppService.GetByName(vencedor.Nome_Participante);
                    var sorteadoEmail = JsonConvert.DeserializeObject <UsuarioViewModel>(sorteado.Content.ReadAsStringAsync().Result);

                    EnviarEmail(sorteadoEmail.Email, sorteadoEmail.Nome, dadosParticipantesSorteio.Nome, dadosParticipantesSorteio.NomeCriador);
                }
                return(View(dadosParticipantesSorteio));;
            }

            var aleatorio         = new Random();
            var participantes     = dadosParticipantesSorteio.SorteioParticipantes;
            var vencedores        = new string[dadosParticipantesSorteio.QtdeItens];
            var contadorRotina    = 0;
            var posicoesSorteadas = new int?[dadosParticipantesSorteio.QtdeItens];

            var sortearNovamente = _sorteioParticipanteAppService.SortearNovamente(idSorteio);

            if (!sortearNovamente.IsSuccessStatusCode)
            {
                return(ErrorMessage("Erro ao zerar Vencedores"));
            }

            do
            {
                var posicao = aleatorio.Next(0, participantes.Count);
                if (!posicoesSorteadas.Contains(posicao))
                {
                    posicoesSorteadas[contadorRotina]    = posicao;
                    vencedores[contadorRotina]           = participantes[posicao].Nome_Participante;
                    dadosParticipantesSorteio.QtdeItens -= 1;
                    _sorteioParticipanteAppService.VencedorParticipantesSorteio(idSorteio, participantes[posicao].Id_Participante);
                    contadorRotina++;

                    var sorteado      = _usuarioAppService.GetByName(participantes[posicao].Nome_Participante);
                    var sorteadoEmail = JsonConvert.DeserializeObject <UsuarioViewModel>(sorteado.Content.ReadAsStringAsync().Result);

                    EnviarEmail(sorteadoEmail.Email, sorteadoEmail.Nome, dadosParticipantesSorteio.Nome, participantes[posicao].Sorteio.NomeCriador);
                }
            } while (dadosParticipantesSorteio.QtdeItens > 0);

            var getVencedores = new SorteioViewModel {
                Nome = dadosParticipantesSorteio.Nome
            };

            foreach (var vencedor in vencedores)
            {
                getVencedores.SorteioParticipantes.Add(new SorteioParticipanteViewModel {
                    Nome_Participante = vencedor
                });
            }

            return(View(getVencedores));
        }
 public SorteioParticipanteViewModel()
 {
     Usuario = new UsuarioViewModel();
     Sorteio = new SorteioViewModel();
 }
 public async Task AtualizarSorteio(SorteioViewModel sorteio)
 {
     await _sorteioHubContext.Clients.All.SendAsync("atualizarSorteio", sorteio);
 }