public async Task AddUserNotifications(UserNotificationBulkRequest request)
        {
            IQueryable <User> users = m_context.Users.Where(x => request.UserIds.Any(id => id == x.Id));

            Data.Models.Notification notification = m_mapper.Map <NotificationMessage, Data.Models.Notification>(request.Message);
            if (notification == null)
            {
                throw new NotificationNotFound($"Уведомление не найдено");
            }
            DateTime date = DateTime.UtcNow;

            foreach (User user in users)
            {
                Data.Models.Notification notification2 = new Data.Models.Notification
                {
                    User     = user,
                    Date     = date,
                    IsClosed = false,
                    Type     = NotificationType.Notification,
                    Text     = notification.Text,
                    Title    = notification.Title,
                    Severity = notification.Severity,
                    Creator  = request.Message.Creator
                };
                m_context.Notifications.Add(notification2);
            }
            await m_context.SaveChangesAsync();
        }
 public ServiceResponse <Data.Models.Notification> CreateNotification(Data.Models.Notification notification)
 {
     try
     {
         _db.Notifications.Add(notification);
         _db.SaveChanges();
         return(new ServiceResponse <Data.Models.Notification>
         {
             IsSuccess = true,
             Message = "New Notification Added",
             Time = DateTime.UtcNow,
             Data = notification
         });
     }
     catch (Exception e)
     {
         return(new ServiceResponse <Data.Models.Notification>
         {
             IsSuccess = false,
             Message = e.StackTrace,
             Time = DateTime.UtcNow,
             Data = null
         });
     }
 }
Example #3
0
        public void AddUserNotificationPositive()
        {
            const string title   = "Hello";
            const string text    = "My message";
            const string creator = "Notification";
            User         user    = Context.Users.First();

            UserNotificationBulkRequest request = new UserNotificationBulkRequest
            {
                UserIds = new List <string> {
                    user.Id
                },
                Message = new Logic.Models.NotificationMessage
                {
                    Title    = title,
                    Text     = text,
                    Creator  = creator,
                    Severity = Logic.Models.Enums.Severity.Informational
                }
            };

            m_notificationService.AddUserNotifications(request);

            Data.Models.Notification notification = Context.Notifications.SingleOrDefault(x => x.Title == title);

            Assert.IsNotNull(notification);
            Assert.AreEqual(user.Id, notification.UserId);
            Assert.AreEqual(text, notification.Text);
            Assert.AreEqual(creator, notification.Creator);
            Assert.AreEqual(NotificationType.Notification, notification.Type);
            Assert.AreEqual(false, notification.IsClosed);
        }
        public async Task SetStatusClosed(string notificationId)
        {
            Data.Models.Notification notification = await m_context.Notifications.SingleOrDefaultAsync(x => x.Id == notificationId);

            if (notification == null)
            {
                throw new NotificationNotFound($"Уведомление не найдено");
            }
            notification.IsClosed = true;
            await m_context.SaveChangesAsync();
        }
        public async Task <UserNotification> GetNotification(string notificationId)
        {
            Data.Models.Notification notification = await m_context.Notifications
                                                    .AsNoTracking()
                                                    .SingleOrDefaultAsync(x => x.Id == notificationId);

            if (notification == null)
            {
                throw new NotificationNotFound($"Уведомление не найдено");
            }
            return(m_mapper.Map <UserNotification>(notification));
        }
Example #6
0
        public void SetStatusClosedPositive()
        {
            User user = Context.Users.First();

            Data.Models.Notification notification = Context.Notifications.First(x => x.IsClosed == false);

            m_notificationService.SetStatusClosed(notification.Id);

            Data.Models.Notification closedNotification = Context.Notifications.SingleOrDefault(x => x.Id == notification.Id);

            Assert.IsNotNull(notification);
            Assert.AreEqual(true, closedNotification.IsClosed);
        }
        public async Task EditNotification(UserNotification userNotification)
        {
            Data.Models.Notification oldNotification = await m_context.Notifications.SingleOrDefaultAsync(x => x.Id == userNotification.NotificationId);

            if (oldNotification == null)
            {
                throw new NotificationNotFound($"Уведомление не найдено");
            }
            m_mapper.Map(userNotification, oldNotification);

            //m_context.Attach(notification);
            //m_context.Entry(notification).State = EntityState.Modified;
            await m_context.SaveChangesAsync();
        }