Exemplo n.º 1
0
        public void Send_Email()
        {
            var newEvent = new Event
            {
                Id = 2,
                Subject = "test",
                Body = "body",
                Category = new Category
                {
                    Id = 1
                },
                CreatedBy = new User
                {
                    Id = 1,
                    Email = "*****@*****.**"
                },
                Date = DateTime.Today,
                From = DateTime.Now.AddHours(-1).TimeOfDay,
                To = DateTime.Now.AddHours(1).TimeOfDay, 
            };

            IUsersRepository userRepository = new FakeUserRepo();
            var mailService = new MailService(userRepository);
            mailService.Send(EventStatus.Removed, newEvent);
        }
Exemplo n.º 2
0
        public IHttpActionResult CreateEvent(Event newEvent)
        {
            eventRepository.Create(newEvent);
            mailService.Send(EventStatus.New, newEvent);

            return Ok();
        }
Exemplo n.º 3
0
 private void SetRecipients(MailMessage message, Event @event)
 {
     var recipients = userRepository.GetEmailsByCategory(@event.Category);
     foreach (var email in recipients)
     {
         message.To.Add(new MailAddress(email));
     }
 }
Exemplo n.º 4
0
 private MailMessage CreateMailMessage(EventStatus status, Event @event)
 {
     var message = new MailMessage
     {
         Subject = PrepareSubject(status),
         Body = PrepareBodyAsHtml(@event),
         From = PrepareSender(@event),
         IsBodyHtml = true
     };
     return message;
 }
Exemplo n.º 5
0
        //public void Create(Event newEvent)
        //{
        //    using (var connection = new SqlConnection(connectionString))
        //    {
        //        connection.Open();
        //        var cmd = new SqlCommand(insertStatement, connection);
        //        cmd.Parameters.Add("Id", SqlDbType.Int).Value = newEvent.Id;
        //        cmd.Parameters.Add("CategoryId", SqlDbType.Int).Value = newEvent.Category.Id;
        //        cmd.Parameters.Add("CreatedBy", SqlDbType.Int).Value = newEvent.CreatedBy.Id;
        //        cmd.Parameters.Add("Date", SqlDbType.Date).Value = newEvent.Date;
        //        cmd.Parameters.Add("TimeFrom", SqlDbType.Time).Value = newEvent.From;
        //        cmd.Parameters.Add("TimeTo", SqlDbType.Time).Value = newEvent.To;
        //        cmd.Parameters.Add("IsAllDayEvent", SqlDbType.Bit).Value = newEvent.IsAllDatEvent;
        //        cmd.Parameters.Add("Subject", SqlDbType.NVarChar).Value = newEvent.Subject;
        //        cmd.Parameters.Add("Body", SqlDbType.NVarChar).Value = newEvent.Body;
        //        cmd.ExecuteNonQuery();
        //    }
        //}


        public void Create(Event newEvent)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Execute(insertStatement, new
                {
                    Id = newEvent.Id,
                    CategoryId = newEvent.Category.Id,
                    CreatedBy = newEvent.CreatedBy.Id,
                    Date = newEvent.Date,
                    TimeFrom = newEvent.From,
                    TimeTo = newEvent.To,
                    IsAllDayEvent = newEvent.IsAllDatEvent,
                    Subject = newEvent.Subject,
                    Body = newEvent.Body
                });
            }
        }
Exemplo n.º 6
0
 public void Create_Event()
 {
     var repo = new EventRepository();
     var newEvent = new Event
     {
         Id = 2,
         Subject = "test",
         Body = "body",
         Category = new Category
         {
             Id = 1
         },
         CreatedBy = new User
         {
             Id = 1,
             Email = "*****@*****.**"
         },
         Date = DateTime.Today,
         From = DateTime.Now.AddHours(-1).TimeOfDay,
         To = DateTime.Now.AddHours(1).TimeOfDay,
     };
     repo.Create(newEvent);
 }
Exemplo n.º 7
0
 public Event GetById(int eventId)
 {
     var newEvent = new Event
     {
         Id = 2,
         Subject = "test fromt fake db",
         Body = "body",
         Category = new Category
         {
             Id = 1
         },
         CreatedBy = new User
         {
             Id = 1,
             Email = "*****@*****.**"
         },
         Date = DateTime.Today,
         From = DateTime.Now.AddHours(-1).TimeOfDay,
         To = DateTime.Now.AddHours(1).TimeOfDay,
     };
     return newEvent;
 }
Exemplo n.º 8
0
 public void Create(Event newEvent)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 private string PrepareBodyAsHtml(Event @event)
 {
     return string.Format("<h2>{0}</h2><p>{1}</p>",
         @event.Subject, @event.Body);
 }
Exemplo n.º 10
0
 private MailAddress PrepareSender(Event @event)
 {
     return new MailAddress(@event.CreatedBy.Email);
 }
Exemplo n.º 11
0
 public void Send(EventStatus status, Event @event)
 { 
     var message = CreateMailMessage(status, @event);
     SetRecipients(message, @event);
     Send(message);
 }