Example #1
0
 private MailMessage CreateMailMessage(NotificationTemplateModel template)
 {
     return(new MailMessage
     {
         From = new MailAddress(this.settings.SmtpFromAddress),
         Subject = template.Title,
         IsBodyHtml = true
     });
 }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var recipientId = await _userService.GetCurrentUserIdAsync();

            var(notifications, loadMore) =
                await _notificationService.GetPagedNotificationsAsync(recipientId);

            var model = new NotificationTemplateModel
            {
                LoadMore                 = loadMore,
                Notifications            = notifications,
                TotalUnReadNotifications = await _notificationService.GetTotalUnReadNotificationsAsync(recipientId)
            };

            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> LoadNotifications(int pageIndex, int pageSize, NotificationTemplateType type)
        {
            var(notifications, loadMore) = await _notificationService.GetPagedNotificationsAsync(
                await _userService.GetCurrentUserIdAsync(),
                pageIndex, pageSize);

            var model = new NotificationTemplateModel
            {
                LoadMore      = loadMore,
                Notifications = notifications
            };

            string template;

            switch (type)
            {
            case NotificationTemplateType.Main:
                template = await _renderService.RenderViewToStringAsync("Templates/_MainNotification", model);

                break;

            case NotificationTemplateType.Mini:

                var liCollection = new List <string>();

                foreach (var notification in notifications)
                {
                    liCollection.Add(
                        await _renderService.RenderViewToStringAsync("Templates/_MiniNotification", notification));
                }

                template = string.Join("", liCollection);
                break;

            default:
                throw new InvalidOperationException(nameof(type));
            }

            return(Json(new
            {
                notifications = template,
                loadMore,
                type
            }));
        }
        public async Task CreateEventNotification_PersistsNewNotification()
        {
            var expectedNotificationBody =
                "Hi Nicola, your appointment with Tesla at 01:45 has been - cancelled for the following reason: We signed a deal with Musk.";
            var eventModel = new EventModel
            {
                EventType = NotificationEventType.AppointmentCancelled,
                UserId    = Guid.NewGuid(),
                Data      = new EventDataModel
                {
                    Firstname           = "Nicola",
                    OrganisationName    = "Tesla",
                    AppointmentDateTime = new DateTime().AddMinutes(105),
                    Reason = "We signed a deal with Musk"
                }
            };
            var notificationTemplateModel = new NotificationTemplateModel
            {
                Id        = Guid.NewGuid(),
                EventType = NotificationEventType.AppointmentCancelled,
                Body      =
                    "Hi {Firstname}, your appointment with {OrganisationName} at {AppointmentDateTime} has been - cancelled for the following reason: {Reason}.",
                Title = "Appointment Cancelled"
            };

            mockNotificationTemplatesAccess.Setup(x => x.GetNotificationTemplate(eventModel.EventType))
            .ReturnsAsync(notificationTemplateModel);
            var sut = new NotificationsService(mockNotificationsAccess.Object, mockNotificationTemplatesAccess.Object);

            await sut.CreateEventNotification(eventModel);

            mockNotificationsAccess.Verify(x => x.SaveNotification(It.Is <NotificationModel>(model =>
                                                                                             model.EventType == eventModel.EventType &&
                                                                                             model.Title == notificationTemplateModel.Title &&
                                                                                             model.UserId == eventModel.UserId &&
                                                                                             model.Body == expectedNotificationBody)));
        }
        public async Task CreateEventNotification_PopulatesGeneratedNotifications_WithSubstitutedTemplateData()
        {
            var expectedNotificationBody =
                "Hi Nicola, your appointment with Tesla at 01:45 has been - cancelled for the following reason: We signed a deal with Musk.";
            var eventModel = new EventModel
            {
                EventType = NotificationEventType.AppointmentCancelled,
                UserId    = Guid.NewGuid(),
                Data      = new EventDataModel
                {
                    Firstname           = "Nicola",
                    OrganisationName    = "Tesla",
                    AppointmentDateTime = new DateTime().AddMinutes(105),
                    Reason = "We signed a deal with Musk"
                }
            };
            var notificationTemplateModel = new NotificationTemplateModel
            {
                Id        = Guid.NewGuid(),
                EventType = NotificationEventType.AppointmentCancelled,
                Body      =
                    "Hi {Firstname}, your appointment with {OrganisationName} at {AppointmentDateTime} has been - cancelled for the following reason: {Reason}.",
                Title = "Appointment Cancelled"
            };

            mockNotificationTemplatesAccess.Setup(x => x.GetNotificationTemplate(eventModel.EventType))
            .ReturnsAsync(notificationTemplateModel);
            var sut = new NotificationsService(mockNotificationsAccess.Object, mockNotificationTemplatesAccess.Object);

            var result = await sut.CreateEventNotification(eventModel);

            Assert.Equal(notificationTemplateModel.Title, result.Title);
            Assert.Equal(notificationTemplateModel.EventType, result.EventType);
            Assert.Equal(eventModel.UserId, result.UserId);
            Assert.Equal(expectedNotificationBody, result.Body);
        }
Example #6
0
        public IActionResult AddNotificationTemplate([FromBody] NotificationTemplateModel model)
        {
            var template = _pimsService.NotificationTemplate.Add(_mapper.Map <Entity.NotificationTemplate>(model));

            return(CreatedAtAction(nameof(GetNotificationTemplate), new { id = template.Id }, _mapper.Map <NotificationTemplateModel>(template)));
        }
Example #7
0
 public IActionResult DeleteNotificationTemplate([FromBody] NotificationTemplateModel model)
 {
     _pimsService.NotificationTemplate.Remove(_mapper.Map <Entity.NotificationTemplate>(model));
     return(new JsonResult(model));
 }
Example #8
0
        public IActionResult UpdateNotificationTemplate([FromBody] NotificationTemplateModel model)
        {
            var template = _pimsService.NotificationTemplate.Update(_mapper.Map <Entity.NotificationTemplate>(model));

            return(new JsonResult(_mapper.Map <NotificationTemplateModel>(template)));
        }