Ejemplo n.º 1
0
        public async Task <bool> SendPushNotifications(PushMessageDto pushMessageDto)
        {
            var result = false;
            var user   = _userService.GetLastUser();

            if (user != null && user.IsAdmin)
            {
                pushMessageDto.Username = user.Username;
                pushMessageDto.Password = user.Password;
                result = await appService.SendNotification(pushMessageDto);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public bool SendNotification(PushMessageDto notification, string rootPath)
        {
            IEnumerable <User> users = new List <User>();

            if (notification.SelectRandom)
            {
                users = userRepository.SelectRandomUsers(_settings.Value.RandomQt);
            }
            else
            {
                users = userRepository.GetUsersSubscribedTo(notification.Tag, notification.Genders, notification.Ages);
            }
            foreach (var user in users)
            {
                var message = new PushMessage()
                {
                    User        = user,
                    Tag         = notification.Title,
                    Date        = notification.Date,
                    Description = notification.Description,
                    Id          = Guid.NewGuid(),
                    Image       = notification.Image,
                };
                messageRepository.InsertMessage(message);
            }

            var saved = messageRepository.SaveChanges();

            if (saved)
            {
                _pushService.SendNotification(new PushSendEntity()
                {
                    Message = notification.Description,
                    Users   = users,
                    Date    = notification.Date,
                    Title   = notification.Title,
                }, rootPath);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> SendNotification(PushMessageDto pushMessageDto)
        {
            var result = await restClientService.PostAsync <PushMessageDto, bool>("api/User/SendNotification", pushMessageDto);

            return(result.Entity);
        }
Ejemplo n.º 4
0
        public IActionResult SendPushNotification([FromBody] PushMessageDto message)
        {
            var result = appServices.SendNotification(message, _hostingEnvironment.ContentRootPath);

            return(Ok(result));
        }