예제 #1
0
 public void TestMailNotification()
 {
     Assert.IsTrue(AdminAccessBll.LoginAdmin(Token));
     var notification = new Notification
     {
         Sender = "*****@*****.**",
         Recipient = "*****@*****.**",
         Subject = "Autogenerated",
         Body = "Do not reply!"
     };
     Assert.IsTrue(AdminAccessBll.SendNotification(Token, notification));
 }
예제 #2
0
 public bool SendNotification(SessionToken token, Notification notification) => AdminAccessDelegate.SendNotification(token, notification);
예제 #3
0
        public override bool SendNotification(SessionToken token, Notification notification)
        {
            if (!IsUserAuthenticated(token) || !IsNotificationValid(notification))
                return false;

            try
            {
                using (var mailMessage = new MailMessage(notification.Sender, notification.Recipient)
                {
                    Subject = notification.Subject,
                    Body = notification.Body,
                    IsBodyHtml = true
                })
                using (var smtpClient = new SmtpClient(EmailNotificationServer, EmailNotificationPort)
                {
                    Credentials = new NetworkCredential(EmailNotificationUsername, EmailNotificationPassword),
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    EnableSsl = true
                })
                {
                    smtpClient.Send(mailMessage);
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
예제 #4
0
        public async void InitializeData()
        {
            AddNewPerformanceCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(new ShowDialogMessage(Locator.PerformanceEditViewModel));
            });
            DeletePerformanceCommand = new RelayCommand<PerformanceViewModel>(p =>
            {
                var result = _adminAccessBll.RemovePerformance(BllAccessHandler.SessionToken, p.ToDomainObject<Performance>());
                if (!result) return;
                Performances.Remove(p);
                AddNotification(p, NotificationType.Removed);
            });
            EditPerformanceCommand = new RelayCommand<PerformanceViewModel>(p =>
            {
                Locator.PerformanceEditViewModel.InitializePreset(
                    p.VenueViewModel, 
                    p.ArtistViewModel, 
                    p.DateTime);
                Messenger.Default.Send(new ShowDialogMessage(Locator.PerformanceEditViewModel));
            });
            SendNotificationsCommand = new RelayCommand(async () =>
            {
                if (NotificationCollection != null)
                {
                    foreach (var notify in NotificationCollection)
                    {
                        var sb = new StringBuilder();
                        foreach (var message in notify.Value)
                        {
                            switch (message.NotificationType)
                            {
                                case NotificationType.Add:
                                    sb.Append("The following event has been assigned: \n");
                                    break;
                                case NotificationType.Modified:
                                    sb.Append("The following event has changed: \n");
                                    break;
                                case NotificationType.Removed:
                                    sb.Append("The following event has been canceled: \n");
                                    break;
                            }
                            sb.Append("Artist: ").Append(message.Performance.ArtistViewModel.Name).AppendLine()
                                .Append("Venue: ").Append(message.Performance.VenueViewModel.Name)
                                .Append(", ")
                                .Append(message.Performance.VenueViewModel.Location.Name).AppendLine()
                                .Append("Date: ")
                                .Append(message.Performance.DateTimeViewModel.DateTime.ToString("dd-MM-yyyy HH:mm"))
                                .AppendLine().AppendLine().Append("---------------------------");
                        }
                        var tmp = new Notification
                        {
                            Recipient = notify.Key,
                            Sender = BllAccessHandler.SessionToken?.User?.EMail,
                            Subject = $"UFO administration notification",
                            Body = sb.ToString()
                        };
                        await _adminAccessBll.SendNotificationAsync(BllAccessHandler.SessionToken, tmp);
                    }
                }
                NotificationCollection = null;
            });

            await Dispatcher.CurrentDispatcher.InvokeAsync(async () =>
            {
                var dates = await _viewAccessBll.GetAllPerformanceDatesAsync();
                CurrentPerformanceDateTime = dates.FirstOrDefault();
                foreach (var dateTime in dates)
                {
                    PerformanceDates.Add(dateTime);
                }
            });
        }