Example #1
0
        public ActionResult Create(InscricaoViewModel collection)
        {
            try
            {
                // TODO: Add insert logic here
                EventoParticipante _result = null;

                if (_eventoParticipanteRepository.VerificarEvento(collection.EventoId, SessionId()))
                {
                    ModelState.AddModelError("EventoId", $"O candidato ja esta inscrito no evento.");
                }
                if (ModelState.IsValid)
                {
                    if (collection.File != null)
                    {
                        var fileName = UploadFile(collection);

                        if (_eventoParticipanteRepository.VerificarEvento(collection.EventoId, SessionId(), true))
                        {
                            _result = _eventoParticipanteRepository.ObterPorEventoParticipante(collection.EventoId, SessionId(), true);
                            _result.Comprovativo = fileName;
                            _result.Removido     = false;
                            _result.Confirmado   = false;
                            _eventoParticipanteRepository.Actualizar(_result);
                        }
                        else
                        {
                            EventoParticipante eventoParticipante = new EventoParticipante
                            {
                                Comprovativo   = fileName,
                                EventoId       = collection.EventoId,
                                ParticipanteId = SessionId()
                            };
                            _eventoParticipanteRepository.Adicionar(eventoParticipante);
                        }
                        var evento = _eventoRepository.ObterPorId(collection.EventoId);
                        if (evento != null)
                        {
                            var  result2 = _membroOrganizadorRepository.ObterPorComissao(evento.ComissaoOrganizadoraId, true);
                            bool state   = false;
                            if (result2 != null)
                            {
                                foreach (var item in result2)
                                {
                                    var participante = _participanteRepository.ObterPorId(SessionId());

                                    if (participante != null)
                                    {
                                        var msg = $"Olá, {item.Membro.Nome}. <br><br> { participante.Nome } fez uma nova inscrição no evento: {evento.Titulo}." +
                                                  $"<br> Em anexo o comprovativo de pagamento.";
                                        var message = new Message(new string[] { item.Membro.Email }, "Nova Inscrição", msg, collection.File);
                                        if (Notificar(message))
                                        {
                                            state = true;
                                        }
                                    }
                                }

                                if (state)
                                {
                                    return(RedirectToAction("Listar", new { msg = "Inscrição criada." }));
                                }
                                else
                                {
                                    ModelState.AddModelError(string.Empty, "Erro ao notificar a comissão organizadora.");
                                }
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, "Erro ao carregar a comissão organizadora.");
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, "Erro ao carregar o evento.");
                        }
                    }
                }
                ViewBag.EventoId = ObterEventos();
                return(View(collection));
            }
            catch
            {
                ViewBag.EventoId = ObterEventos();
                return(View(collection));
            }
        }
 public EventoParticipante Adicionar(EventoParticipante entity)
 {
     return(_eventoParticipanteRepository.Adicionar(entity));
 }