public ActionResult ModeratorMail(InboxType type, string subName = null, int? pageNumber = null, int? pageSize = null) { ViewBag.ManageNavigationKey = "moderatormail"; if (pageNumber == null || pageNumber < 1) pageNumber = 1; if (pageSize == null) pageSize = 25; if (pageSize > 100) pageSize = 100; if (pageSize < 1) pageSize = 1; var skip = (pageNumber - 1) * pageSize; var take = pageSize; var moderatingSubs = _moderationDao.GetSubsModeratoredByUserWithPermissions(_userContext.CurrentUser.Id); var model = new InboxViewModel { InboxType = type }; model.IsModerator = moderatingSubs.Count > 0; if (!string.IsNullOrEmpty(subName)) { var sub = _subDao.GetSubByName(subName); if (sub == null) throw new NotFoundException(); // make the sure that the user is allowed to see this mod mail if (!_userContext.CurrentUser.IsAdmin) { if (!moderatingSubs.ContainsKey(sub.Id)) throw new UnauthorizedException(); if (!moderatingSubs[sub.Id].HasPermission(ModeratorPermissions.Mail)) throw new UnauthorizedException(); } model.Sub = sub; model.ModeratorMailForSubs = new List<Guid> { sub.Id }; } else { model.ModeratorMailForSubs = new List<Guid>(); foreach (var key in moderatingSubs.Keys) { if (moderatingSubs[key].HasPermission(ModeratorPermissions.Mail)) model.ModeratorMailForSubs.Add(key); } } SeekedList<Guid> messages; if (moderatingSubs.Count == 0) messages = new SeekedList<Guid>(); else switch (type) { case InboxType.ModeratorMail: messages = _messageDao.GetModeratorMailForSubs(moderatingSubs.Select(x => x.Key).ToList(), skip, take); break; case InboxType.ModeratorMailUnread: messages = _messageDao.GetUnreadModeratorMailForSubs(moderatingSubs.Select(x => x.Key).ToList(), skip, take); break; case InboxType.ModeratorMailSent: messages = _messageDao.GetSentModeratorMailForSubs(moderatingSubs.Select(x => x.Key).ToList(), skip, take); break; default: throw new Exception("invalid type"); } model.Messages = new PagedList<MessageWrapped>(_messageWrapper.Wrap(messages, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, messages.HasMore); return View(model); }
public ActionResult Sent(int? pageNumber, int? pageSize) { ViewBag.ManageNavigationKey = "sent"; if (pageNumber == null || pageNumber < 1) pageNumber = 1; if (pageSize == null) pageSize = 25; if (pageSize > 100) pageSize = 100; if (pageSize < 1) pageSize = 1; var skip = (pageNumber - 1) * pageSize; var take = pageSize; var messages = _messageDao.GetSentMessagesForUser(_userContext.CurrentUser.Id, skip, take); var model = new InboxViewModel(); model.InboxType = InboxType.Sent; model.IsModerator = _moderationDao.GetSubsModeratoredByUser(_userContext.CurrentUser.Id).Count > 0; model.Messages = new PagedList<MessageWrapped>(_messageWrapper.Wrap(messages, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, messages.HasMore); return View(model); }
public ActionResult Inbox(InboxType type, int? pageNumber, int? pageSize) { ViewBag.ManageNavigationKey = "inbox"; if (pageNumber == null || pageNumber < 1) pageNumber = 1; if (pageSize == null) pageSize = 25; if (pageSize > 100) pageSize = 100; if (pageSize < 1) pageSize = 1; var skip = (pageNumber - 1) * pageSize; var take = pageSize; SeekedList<Guid> messages; switch (type) { case InboxType.All: messages = _messageDao.GetAllMessagesForUser(_userContext.CurrentUser.Id, skip, take); break; case InboxType.Unread: messages = _messageDao.GetUnreadMessagesForUser(_userContext.CurrentUser.Id, skip, take); break; case InboxType.Messages: messages = _messageDao.GetPrivateMessagesForUser(_userContext.CurrentUser.Id, skip, take); break; case InboxType.CommentReplies: messages = _messageDao.GetCommentRepliesForUser(_userContext.CurrentUser.Id, skip, take); break; case InboxType.PostReplies: messages = _messageDao.GetPostRepliesForUser(_userContext.CurrentUser.Id, skip, take); break; case InboxType.Mentions: messages = _messageDao.GetMentionsForUser(_userContext.CurrentUser.Id, skip, take); break; default: throw new Exception("Unknown inbox type"); } var model = new InboxViewModel(); model.InboxType = type; model.IsModerator = _moderationDao.GetSubsModeratoredByUser(_userContext.CurrentUser.Id).Count > 0; model.Messages = new PagedList<MessageWrapped>(_messageWrapper.Wrap(messages, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, messages.HasMore); return View(model); }