本文整理汇总了C#中IJabbrRepository.GetNotificationsByUser方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.GetNotificationsByUser方法的具体用法?C# IJabbrRepository.GetNotificationsByUser怎么用?C# IJabbrRepository.GetNotificationsByUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJabbrRepository
的用法示例。
在下文中一共展示了IJabbrRepository.GetNotificationsByUser方法的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)
//.........这里部分代码省略.........
示例2: GetNotifications
private static IPagedList<NotificationViewModel> GetNotifications(IJabbrRepository repository, ChatUser user, bool all = false,
int page = 1, int take = 20, string roomName = null)
{
IQueryable<Notification> notificationsQuery = repository.GetNotificationsByUser(user, true);
if (!all)
{
notificationsQuery = notificationsQuery.Unread();
}
if (!String.IsNullOrWhiteSpace(roomName))
{
var room = repository.VerifyRoom(roomName);
if (room != null)
{
notificationsQuery = notificationsQuery.ByRoom(roomName);
}
}
return notificationsQuery.OrderByDescending(n => n.Message.When)
.Select(n => new NotificationViewModel()
{
NotificationKey = n.Key,
FromUserName = n.Message.User.Name,
FromUserImage = n.Message.User.Hash,
Message = n.Message.Content,
HtmlEncoded = n.Message.HtmlEncoded,
RoomName = n.Room.Name,
Read = n.Read,
When = n.Message.When
})
.ToPagedList(page, take);
}