/// <summary>
        /// Create the notification.
        /// </summary>
        /// <param name="notification">Notification.</param>
        /// <returns>int</returns>
        public async Task <NotificationDTO> CreateNotification(NotificationDTO notification)
        {
            using (var context = new NotificationsContext())
            {
                var newNotification = new Notification
                {
                    Id          = notification.Id,
                    Channel     = notification.Channel,
                    Receiver    = notification.Receiver,
                    Type        = notification.Type,
                    Title       = notification.Title,
                    Body        = notification.Body,
                    IsReaded    = notification.IsReaded,
                    CreatedDate = DateTime.Now,
                    Protocol    = notification.Protocol
                };

                context.Notifications.Add(newNotification);

                await context.SaveChangesAsync();

                notification.Id          = newNotification.Id;
                notification.CreatedDate = newNotification.CreatedDate;

                return(notification);
            }
        }
 /// <summary>
 /// Get the count of unreaded notifications by user login.
 /// </summary>
 /// <param name="userLogin">The user login.</param>
 /// <returns>int</returns>
 public async Task <int> GetCountOfUnreadedNotifications(string userLogin)
 {
     using (var context = new NotificationsContext())
     {
         return(await context.Notifications.Where(t => (t.Receiver == userLogin) && (t.IsReaded == false)).CountAsync());
     }
 }
        public ActionResult Index()
        {
            using (var db = new NotificationsContext())
            {
                var list = db.Notifications.ToList();

                return(View(list));
            }
        }
 /// <summary>
 /// Set notification as Readed.
 /// </summary>
 /// <param name="notificationId">The notification Id.</param>
 /// <returns>void</returns>
 public async Task SetNotificationAsReaded(int notificationId)
 {
     using (var context = new NotificationsContext())
     {
         var notificationToEdit = context.Notifications.FirstOrDefault(t => t.Id == notificationId);
         if (notificationToEdit != null)
         {
             notificationToEdit.IsReaded = true;
             await context.SaveChangesAsync();
         }
     }
 }
 /// <summary>
 /// Get notifications by user login.
 /// </summary>
 /// <param name="userLogin">The receiver login.</param>
 /// <param name="onlyUnReaded">Take only unreaded notifications.</param>
 /// <returns>IEnumerable\<NotificationDTO\></returns>
 public async Task <IEnumerable <NotificationDTO> > GetNotificationsByReceiver(string userLogin, bool onlyUnReaded = false)
 {
     using (var context = new NotificationsContext())
     {
         return(await context.Notifications.Where(t => t.Receiver == userLogin && ((t.IsReaded == false) || !onlyUnReaded)).OrderByDescending(t => t.Id)
                .Select(t => new NotificationDTO
         {
             Id = t.Id,
             Channel = t.Channel,
             Receiver = t.Receiver,
             Type = t.Type,
             Title = t.Title,
             Body = t.Body,
             IsReaded = t.IsReaded,
             CreatedDate = t.CreatedDate,
             Protocol = t.Protocol
         }).ToListAsync());
     }
 }
        public async Task <Notification> Handle(QueryNotificationRequest request, CancellationToken cancellationToken)
        {
            using var dbContext = new NotificationsContext();
            var notification = await dbContext.Notification.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (notification == null)
            {
                return(null);
            }

            var      xml          = XDocument.Parse(notification.Payload);
            XElement imageElement = xml.XPathSelectElement($".//image");

            var imageSource = (string)imageElement?.Attribute("src");

            return(new Notification
            {
                Id = notification.Id,
                Group = notification.Group,
                ImageSource = imageSource
            });
        }
 public NotificationsController(NotificationsContext context)
 {
     _context = context;
 }
Exemple #8
0
 public SubscriptionsRepository(NotificationsContext notificationsContext,
                                IMapper mapper)
 {
     db          = notificationsContext;
     this.mapper = mapper;
 }
Exemple #9
0
 public SendEmailCommandHandler(NotificationsContext context)
 {
     _context = context;
 }
 public NotificationsController(NotificationsContext db)
 {
     _db = db;
 }
 public NotificationsRepository(NotificationsContext context)
     : base(context)
 {
 }
Exemple #12
0
 public GetSentEmailsCountQueryHandler(NotificationsContext context)
 {
     _context = context;
 }