Esempio n. 1
0
        public Task SendAsync(UserNotification userNotification)
        {
            var dto = UserNotificationDto.FromDomainObject(userNotification);

            var userId = $"{userNotification.AppId}_{userNotification.UserId}";

            return(hubContext.Clients.User(userId).SendAsync("notification", dto));
        }
Esempio n. 2
0
        public IActionResult Put(int id, UserNotificationDto notificationDto)
        {
            var notification = _mapper.Map <UserNotification>(notificationDto);

            notification.Id = id;

            var result   = _notificationService.UpdateNotification(notification);
            var response = new ApiResponse <bool>(result);

            return(Ok(response));
        }
Esempio n. 3
0
        public async Task <ActionResult> UpdateNotificationsAsync(UserNotificationDto userNotifications)
        {
            if (ModelState.IsValid)
            {
                await _userService.UpdateNotificationsAsync(userNotifications);

                return(Ok());
            }

            return(BadRequest(ModelState));
        }
Esempio n. 4
0
        public async Task UpdateNotificationsAsync(UserNotificationDto userNotifications)
        {
            var userId = _userProvider.GetUserId();
            var user   = await _userRepository.GetByIdAsync(userId);

            user.NewVendorNotificationIsOn    = userNotifications.NewVendorNotificationIsOn;
            user.NewDiscountNotificationIsOn  = userNotifications.NewDiscountNotificationIsOn;
            user.HotDiscountsNotificationIsOn = userNotifications.HotDiscountsNotificationIsOn;
            user.AllNotificationsAreOn        = userNotifications.AllNotificationsAreOn;

            user.TagNotifications      = userNotifications.TagNotifications;
            user.CategoryNotifications = userNotifications.CategoryNotifications;
            user.VendorNotifications   = userNotifications.VendorNotifications;

            await _userRepository.UpdateAsync(user);
        }
        public void Notify(NotifyUserMessage message)
        {
            lock (_lock)
            {
                var dto = new UserNotificationDto
                {
                    Timestamp = DateTime.UtcNow,
                    Message   = message.Notification
                };

                _notifications.RemoveAll(n => n.Message.Equals(message.Notification, StringComparison.Ordinal));
                _notifications.Add(dto);

                var context = GlobalHost.ConnectionManager.GetHubContext <UserNotificationHub>();
                context.Clients?.All?.onNotification(dto);
            }
        }
Esempio n. 6
0
        public async Task CanUpdateNotificationsAsync()
        {
            Data.Add(_user.DeepClone());
            _user.VendorNotifications.Insert(0, Guid.NewGuid());

            var notifications = new UserNotificationDto
            {
                AllNotificationsAreOn        = _user.AllNotificationsAreOn,
                NewDiscountNotificationIsOn  = _user.NewVendorNotificationIsOn,
                HotDiscountsNotificationIsOn = _user.HotDiscountsNotificationIsOn,
                NewVendorNotificationIsOn    = _user.NewVendorNotificationIsOn,
                CategoryNotifications        = _user.CategoryNotifications,
                TagNotifications             = _user.TagNotifications,
                VendorNotifications          = _user.VendorNotifications
            };

            await _controller.UpdateNotificationsAsync(notifications);

            Assert.Equal(3, Data.Single(x => x.Id == _user.Id).VendorNotifications.Count);
        }
Esempio n. 7
0
        public IEnumerable <UserNotificationDto> GetNotifications()
        {
            var userId        = User.Identity.GetUserId();
            var notifications = _context.UserNotifications.Where(n => n.RecipientId == userId).ToList();
            var dtos          = new List <UserNotificationDto>();


            foreach (var notification in notifications)
            {
                var dto = new UserNotificationDto
                {
                    Sender       = notification.Sender,
                    CustomerName = notification.CustomerName,
                    Body         = notification.Body,
                    IsRead       = notification.IsRead,
                    CustomerId   = notification.CustomerId
                };

                dtos.Add(dto);
            }
            return(dtos);
        }