Ejemplo n.º 1
0
        public bool AlteraçoesEvento(MotivoCancelamentoEvento motivo)
        {
            bool result            = false;
            var  eventoSelecionado = Db.Evento.Find(motivo.EventoId);

            var eventosParticipante = Db.ParticipanteEvento.Where(x => x.EventoId == eventoSelecionado.Id).ToList();

            if (eventoSelecionado == null)
            {
                return(false);
            }

            foreach (var item in eventosParticipante)
            {
                var usuario = Db.Usuario.Find(item.ParticipanteId);

                GmailEmailService gmail = new GmailEmailService();
                EmailMessage      msg   = new EmailMessage
                {
                    Body    = $"<html><head> </head> <body>  <form> <h1>Aviso</h1><h3>Olá {usuario.Nome}</h3><p>{motivo.Descricao}</p> </form></body> </html>",
                    IsHtml  = true,
                    Subject = "Cancelamento de Evento",
                    ToEmail = usuario.Email
                };

                result = gmail.SendEmailMessage(msg);
            }

            if (result)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public string CancelarEvento(MotivoCancelamentoEvento motivo)
        {
            try
            {
                bool result            = false;
                var  eventoSelecionado = Db.Evento.Find(motivo.EventoId);

                if (eventoSelecionado == null)
                {
                    throw new Exception("Evento não encontrado.");
                }

                eventoSelecionado.Cancelado = true;

                Db.Evento.Attach(eventoSelecionado);
                Db.Entry(eventoSelecionado).State = EntityState.Modified;
                Db.SaveChanges();


                var eventosParticipante = Db.ParticipanteEvento.Where(x => x.EventoId == eventoSelecionado.Id).ToList();

                foreach (var item in eventosParticipante)
                {
                    var usuario = Db.Usuario.Find(item.ParticipanteId);

                    GmailEmailService gmail = new GmailEmailService();
                    EmailMessage      msg   = new EmailMessage
                    {
                        Body    = $"<html><head> </head> <body>  <form> <h1>Aviso</h1><h3>Olá {usuario.Nome}</h3><p>{motivo.Descricao}</p> </form></body> </html>",
                        IsHtml  = true,
                        Subject = "O Evento " + eventoSelecionado.Nome + "foi cancelado",
                        ToEmail = usuario.Email
                    };

                    result = gmail.SendEmailMessage(msg);
                }

                return("OK");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }