Exemplo n.º 1
0
        //
        // GET: Forum/EditMessage/Groupid&ThreadId&MessageId
        public async Task <ActionResult> EditMessage(int groupId, int threadId, int messageId)
        {
            // Just sending the id too the viewbag so if we need them in the view we have them
            ViewBag.GroupId   = groupId;
            ViewBag.ThreadId  = threadId;
            ViewBag.MessageId = messageId;

            Message message = await MessageManager.FindByIdAsync(messageId);

            // The model for the orgirinal message
            // Creating the block
            MessagesViewModel messageModel = new MessagesViewModel
            {
                Id            = message.Id,
                UserName      = message.User.UserName,
                JoinDate      = message.User.JoinDate,
                Posts         = message.User.PostsCount,
                Signiture     = message.User.Signature,
                Reputation    = message.Reputation,
                ThreadId      = threadId,
                GroupId       = groupId,
                Image         = ProfilePictureSystem.GetProfilePicture(message.User.UserId),
                Country       = (await UserManager.FindByIdAsync(message.User.UserId)).Country,
                Body          = message.Body,
                MessagePost   = message.TimeStamp,
                MessageNumber = message.MessagePlacementInThread
            };

            // This will be passed true to the partial view
            ViewBag.MessageModel = messageModel;

            return(View());
        }
Exemplo n.º 2
0
        //
        // GET: Forum/Thread/ThreadId&GroupId
        public async Task <ActionResult> Thread(int threadId, int groupId, int?page)
        {
            const int messagesPerPage = 20;

            // Filling in the viewbags
            ViewBag.GroupName = await GroupManager.GetGroupNameByIdAsync(groupId);

            ViewBag.GroupId  = groupId;
            ViewBag.ThreadId = threadId;

            // Creating a list of messages
            ThreadViewModel model  = new ThreadViewModel();
            Thread          thread = await ThreadManager.FindByIdAsync(threadId);

            ICollection <MessagesViewModel> messagesViewModels = new List <MessagesViewModel>();

            model.ThreadName = thread.Name;

            // TODO: make this so this is only if the user is loged in
            model.Subscribed = ThreadManager.IsUserSubscribedToThreac(thread);

            // Creating the messages
            foreach (Message message in thread.Messages)
            {
                messagesViewModels.Add(new MessagesViewModel
                {
                    Id            = message.Id,
                    UserName      = UserManager.FindById(message.User.UserId).UserName,
                    JoinDate      = message.User.JoinDate,
                    Posts         = message.User.PostsCount,
                    Signiture     = message.User.Signature,
                    Reputation    = message.Reputation,
                    ThreadId      = threadId,
                    GroupId       = groupId,
                    Image         = ProfilePictureSystem.GetProfilePicture(message.User.UserId),
                    Country       = (await UserManager.FindByIdAsync(message.User.UserId)).Country,
                    VotingEnabled = ReputationSystem.CanUserVote(message),
                    IsCreator     = (message.User.UserId == User.Identity.GetUserId()),

                    Body          = message.Body,
                    MessagePost   = message.TimeStamp,
                    MessageNumber = message.MessagePlacementInThread
                });
            }

            // Sorts the list by date
            messagesViewModels = messagesViewModels.OrderByDescending(m => m.MessagePost).ToList();

            // Changing to it a page list
            model.Messages = messagesViewModels.ToPagedList(page ?? 1, messagesPerPage);

            // Increase the view count
            await ThreadManager.AddThreadViewwCountAsync(thread.Id);

            return(View(model));
        }
Exemplo n.º 3
0
        //
        // GET: Forum\ForumProfile
        public async Task <ActionResult> ForumProfile(string userName)
        {
            ForumUser user = await ForumUserManager.FindByUserNameAsync(userName);

            ForumProfleViewModel model = new ForumProfleViewModel
            {
                UserName       = user.UserName,
                ProfilePicture = ProfilePictureSystem.GetProfilePicture(user.UserId),
                PostCount      = user.PostsCount,
                Reputation     = user.Reputation,
                BaseRole       = user.User.PrimaryRole
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> UserProfile(string username)
        {
            // Get the user
            ForumUser forumUser = await ForumUserManager.FindByUserNameAsync(username);

            User user = forumUser.User;

            // Populate the model
            UserProfileViewModel model = new UserProfileViewModel()
            {
                UserName     = user.UserName,
                Reputation   = forumUser.Reputation,
                Postcount    = forumUser.PostsCount,
                Role         = user.PrimaryRole,
                LastActivity = forumUser.LastActivity,
                JoinDate     = forumUser.JoinDate,
                Country      = user.Country,
                Seniorty     = user.Seniority,
                Image        = ProfilePictureSystem.GetProfilePicture(user.Id),
            };

            return(View(model));
        }