コード例 #1
0
        public DAL.App.DTO.Notification AddNewNotification(DAL.App.DTO.Notification notification)
        {
            var domainNotification = NotificationMapper.MapToDomain(notification);
            var addedNotification  = RepoDbSet.Add(domainNotification).Entity;

            return(NotificationMapper.Map(addedNotification));
        }
コード例 #2
0
        public async Task <DAL.App.DTO.Notification> FindByTrainingAndUserId(Guid userId, Guid trainingId)
        {
            var notification = RepoDbSet.AsQueryable()
                               .Where(n => n.AppUserId == userId && n.TrainingId == trainingId)
                               .FirstOrDefaultAsync();

            return(NotificationMapper.Map(await notification));
        }
コード例 #3
0
        public async Task <DAL.App.DTO.Notification> UpdateNotification(DAL.App.DTO.Notification notification)
        {
            var domain = await RepoDbSet.FindAsync(notification.Id);

            domain.Recived = true;
            var addedNotification = RepoDbSet.Update(domain).Entity;

            return(NotificationMapper.Map(addedNotification));
        }
コード例 #4
0
        public async Task <DTO.Notification> FirstOrDefaultAsync(Guid id, Guid?userId = null)
        {
            var query = RepoDbSet.Where(a => a.Id == id).AsQueryable();

            if (userId != null)
            {
                query = query.Where(a => a.AppUserId == userId);
            }

            return(NotificationMapper.Map(await query.FirstOrDefaultAsync()));
        }
コード例 #5
0
        private void Notify(WebSocketConnectionBase connection, DeviceNotification notification, Device device)
        {
            var user = (User)connection.Session["user"];

            if (user == null || !IsNetworkAccessible(device.NetworkID, user))
            {
                return;
            }

            connection.SendResponse("notification/insert",
                                    new JProperty("deviceGuid", device.GUID),
                                    new JProperty("notification", NotificationMapper.Map(notification)));
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            SuggestionMapper.Map(modelBuilder);
            SuggestionVoteMapper.Map(modelBuilder);
            SuggestionCommentMapper.Map(modelBuilder);

            ItemMapper.Map(modelBuilder);
            ItemPropertyMapper.Map(modelBuilder);

            NotificationMapper.Map(modelBuilder);

            UserMapper.Map(modelBuilder);
            UserNotificationSettingMapper.Map(modelBuilder);
            UserNotificationMapper.Map(modelBuilder);
        }
コード例 #7
0
        public void InsertDeviceNotification(JObject notification)
        {
            if (notification == null)
            {
                throw new WebSocketRequestException("Please specify notification");
            }

            var notificationEntity = NotificationMapper.Map(notification);

            notificationEntity.Device = CurrentDevice;
            Validate(notificationEntity);

            DataContext.DeviceNotification.Save(notificationEntity);
            _messageManager.ProcessNotification(notificationEntity);
            _messageBus.Notify(new DeviceNotificationAddedMessage(CurrentDevice.ID, notificationEntity.ID));

            notification = NotificationMapper.Map(notificationEntity);
            SendResponse(new JProperty("notification", notification));
        }
コード例 #8
0
        /// <inheritdoc />
        /// <summary>
        /// Send Notification
        /// </summary>
        /// <param name="usersIds"></param>
        /// <param name="notification"></param>
        /// <returns></returns>
        public virtual async Task SendNotificationAsync(IEnumerable <Guid> usersIds, Notification notification)
        {
            if (notification == null)
            {
                throw new NullReferenceException();
            }
            try
            {
                var users = usersIds.ToList();
                if (!users.Any())
                {
                    return;
                }
                if (!notification.SendLocal && !notification.SendEmail)
                {
                    return;
                }
                var emails = new HashSet <string>();
                foreach (var userId in users)
                {
                    var user = await _userManager.UserManager.FindByIdAsync(userId.ToString());

                    if (user == null)
                    {
                        continue;
                    }
                    //send email only if email was confirmed
                    if (notification.SendEmail && user.EmailConfirmed)
                    {
                        emails.Add(user.Email);
                    }

                    if (!notification.SendLocal)
                    {
                        continue;
                    }
                    notification.Id     = Guid.NewGuid();
                    notification.UserId = userId;
                    var tenant = await _userManager.IdentityContext.Tenants.FirstOrDefaultAsync(x => x.Id.Equals(user.TenantId));

                    var response = await _dataService.Add <SystemNotifications>(_dataService.GetDictionary(notification), tenant.MachineName);

                    if (!response.IsSuccess)
                    {
                        _logger.LogError("Fail to add new notification in database");
                    }
                }
                if (notification.SendLocal)
                {
                    _hub.SendNotification(users, NotificationMapper.Map(notification));
                }
                if (notification.SendEmail)
                {
                    await _emailSender.SendEmailAsync(emails, notification.Subject, notification.Content);
                }
            }
            catch (Exception e)
            {
                _logger.LogCritical(e.Message);
            }
        }
コード例 #9
0
 public async Task <ActionResult <IEnumerable <V1DTO.NotificationDTO> > > GetNotifications()
 {
     return(Ok((await _bll.Notifications.GetAllAsync()).Select(e => _mapper.Map(e))));
 }