本文整理汇总了C#中IJabbrRepository.GetNotificationById方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.GetNotificationById方法的具体用法?C# IJabbrRepository.GetNotificationById怎么用?C# IJabbrRepository.GetNotificationById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJabbrRepository
的用法示例。
在下文中一共展示了IJabbrRepository.GetNotificationById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
//.........这里部分代码省略.........