Beispiel #1
0
        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));
        }