예제 #1
0
        public async Task <IActionResult> Timeline()
        {
            ViewData["title"] = "Timeline";

            var messages = await _timelineService.GetFollowerMessagesForUser(User.GetUserID(), ResultsPerPage);

            var mapped = messages.Select(message => new TimelineMessageVM(
                                             message.ID,
                                             new UserVM(
                                                 message.Author.ID,
                                                 message.Author.Username,
                                                 message.Author.Email),
                                             message.Text,
                                             message.PublishDate,
                                             message.IsFlagged
                                             )).ToList();

            var vm = new UserTimelineVM(
                new UserVM(
                    User.GetUserID(),
                    User.GetUsername(),
                    User.GetEmail()
                    ),
                false,
                mapped
                );

            return(View("Timeline", vm));
        }
예제 #2
0
        public async Task <IActionResult> UserTimeline(string username)
        {
            try
            {
                var author = await _userService.GetUserFromUsername(username);

                if (author == null)
                {
                    return(NotFound());
                }

                var includeFlaggedMessages = User.IsInRole(AuthRoles.Administrator);
                var messages = await _timelineService.GetMessagesForUser(author.Username, ResultsPerPage, includeFlaggedMessages);

                var isUserFollowing = await _userService.IsUserFollowing(User.GetUserID(), username);

                var mapped = messages.Select(message => new TimelineMessageVM(
                                                 message.ID,
                                                 new UserVM(
                                                     message.Author.ID,
                                                     message.Author.Username,
                                                     message.Author.Email
                                                     ),
                                                 message.Text,
                                                 message.PublishDate,
                                                 message.IsFlagged
                                                 )).ToList();

                var vm = new UserTimelineVM(
                    new UserVM(
                        author.ID,
                        author.Username,
                        author.Email),
                    isUserFollowing,
                    mapped
                    );

                ViewData["title"] = $"{author.Username}'s Timeline";

                return(View(nameof(UserTimeline), vm));
            }
            catch (UnknownUserException e)
            {
                return(BadRequest(new ErrorResponse(e)));
            }
        }
예제 #3
0
        public async Task <IActionResult> PublicTimeline()
        {
            ViewData["title"] = "Public Timeline";

            var includeFlaggedMessages = User.IsInRole(AuthRoles.Administrator);

            var messages = await _timelineService.GetMessagesForAnonymousUser(ResultsPerPage, includeFlaggedMessages);

            var mapped = messages.Select(message => new TimelineMessageVM(
                                             message.ID,
                                             new UserVM(
                                                 message.Author.ID,
                                                 message.Author.Username,
                                                 message.Author.Email),
                                             message.Text,
                                             message.PublishDate,
                                             message.IsFlagged
                                             )).ToList();

            var vm = new UserTimelineVM(null, false, mapped);

            return(View("Timeline", vm));
        }