当前位置: 首页>>代码示例>>C#>>正文


C# IJabbrRepository.GetUnreadNotificationsCount方法代码示例

本文整理汇总了C#中IJabbrRepository.GetUnreadNotificationsCount方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.GetUnreadNotificationsCount方法的具体用法?C# IJabbrRepository.GetUnreadNotificationsCount怎么用?C# IJabbrRepository.GetUnreadNotificationsCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IJabbrRepository的用法示例。


在下文中一共展示了IJabbrRepository.GetUnreadNotificationsCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NotificationsModule

        public NotificationsModule(IJabbrRepository repository,
                                   IChatService chatService,
                                   IChatNotificationService notificationService)
            : base("/notifications")
        {
            Get["/"] = _ =>
            {
                if (!IsAuthenticated)
                {
                    return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));
                }

                var request = this.Bind<NotificationRequestModel>();

                ChatUser user = repository.GetUserById(Principal.GetUserId());
                int unreadCount = repository.GetUnreadNotificationsCount(user);
                IPagedList<NotificationViewModel> notifications = GetNotifications(repository, user, all: request.All, page: request.Page, roomName: request.Room);

                var viewModel = new NotificationsViewModel
                {
                    ShowAll = request.All,
                    UnreadCount = unreadCount,
                    Notifications = notifications,
                    DebugMode = (bool)Context.Items["_debugMode"],
                };

                return View["index", viewModel];
            };

            Post["/markasread"] = _ =>
            {
                if (!IsAuthenticated)
                {
                    return HttpStatusCode.Forbidden;
                }

                int notificationId = Request.Form.notificationId;

                Notification notification = repository.GetNotificationById(notificationId);

                if (notification == null)
                {
                    return HttpStatusCode.NotFound;
                }

                ChatUser user = repository.GetUserById(Principal.GetUserId());

                if (notification.UserKey != user.Key)
                {
                    return HttpStatusCode.Forbidden;
                }

                notification.Read = true;
                repository.CommitChanges();

                notificationService.MessageReadStateChanged(user, notification.Message, notification);
                UpdateUnreadCountInChat(repository, notificationService, user);

                var response = Response.AsJson(new { success = true });

                return response;
            };

            Post["/markallasread"] = _ =>
            {
                if (!IsAuthenticated)
                {
                    return HttpStatusCode.Forbidden;
                }

                ChatUser user = repository.GetUserById(Principal.GetUserId());
                IList<Notification> unReadNotifications = repository.GetNotificationsByUser(user).Unread().ToList();

                if (!unReadNotifications.Any())
                {
                    return HttpStatusCode.NotFound;
                }

                foreach (var notification in unReadNotifications)
                {
                    notification.Read = true;
                    notificationService.MessageReadStateChanged(user, notification.Message, notification);
                }

                repository.CommitChanges();

                UpdateUnreadCountInChat(repository, notificationService, user);

                var response = Response.AsJson(new { success = true });

                return response;
            };

            Get["/{key}"] = _ =>
            {
                if (!IsAuthenticated)
                    return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));

                var notification = repository.GetNotificationById(_.key);
                if (notification == null)
//.........这里部分代码省略.........
开发者ID:Widdershin,项目名称:vox,代码行数:101,代码来源:NotificationsModule.cs

示例2: UpdateUnreadCountInChat

 private static void UpdateUnreadCountInChat(IJabbrRepository repository, IChatNotificationService notificationService,
                                             ChatUser user)
 {
     var unread = repository.GetUnreadNotificationsCount(user);
     notificationService.UpdateUnreadMentions(user, unread);
 }
开发者ID:Widdershin,项目名称:vox,代码行数:6,代码来源:NotificationsModule.cs


注:本文中的IJabbrRepository.GetUnreadNotificationsCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。