コード例 #1
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = BuildPostReplies(post.Replies);

            var model = new PostIndexModel
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ImageUrl,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies,
                ForumId        = post.Forum.Id,
                ForumName      = post.Forum.Title,
                ForumImage     = post.Forum.ImageUrl,
                IsAuthorAdmin  = IsAuthorAdmin(post.User),
                EditedCreated  = post.EditedDate,
                IsEdited       = post.IsEdited
            };

            return(View(model));
        }
コード例 #2
0
        public IActionResult Index(int postId)
        {
            var post = _postService.GetById(postId);

            var replies = post.Replies.Select(r => new PostReplyViewModel
            {
                Id             = r.Id,
                AuthorName     = r.User.UserName,
                AuthorId       = r.User.Id,
                AuthorImageUrl = r.User.ProfileImageUrl,
                AuthorRating   = r.User.Rating,
                Created        = r.Created,
                ReplyContent   = r.Content,
                IsAuthorAdmin  = _userManager.GetRolesAsync(r.User).Result.Contains("admin")
            });

            var model = new PostIndexModel
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies,
                ForumTopic     = post.Forum.Title,
                ForumId        = post.Forum.Id,
                IsAuthorAdmin  = _userManager.GetRolesAsync(post.User).Result.Contains("admin")
            };

            return(View(model));
        }
コード例 #3
0
ファイル: PostController.cs プロジェクト: sjarske/Forum1
        public IActionResult Index(int id)
        {
            int userid;
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;

            try
            {
                userid = int.Parse(claims.ElementAt(2).Value);
            }
            catch (Exception)
            {
                userid = 0;
            }
            var post    = _post.GetById(id);
            var user    = _user.GetById(post.User.Id);
            var forum   = _forum.GetById(post.Forum.Id);
            var replies = _postReply.GetById(post.Id);
            var model   = new PostIndexModel
            {
                RatedByUser = _post.CheckLikeByUserId(userid, id),
                Rating      = _post.GetRatingById(id),
                Post        = post,
                User        = user,
                Forum       = forum,
                Replies     = replies
            };

            return(View(model));
        }
コード例 #4
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = BuildPostReplies(post.Replies);

            var model = new PostIndexModel
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                Content        = post.Content,
                Replies        = replies,
                ForumId        = post.Forum.Id,
                ForumName      = post.Forum.Title,
                IsAdmin        = IsAuthorAdmin(post.User),
                IsModerator    = IsAuthorModerator(post.User),
                PostReplyCount = _postService.GetPostReplyCount(post.Id)
            };

            return(View(model));
        }
コード例 #5
0
        public IActionResult Index(int id)
        {
            var post = _servicePost.GetById(id);

            var model = new PostIndexModel
            {
                Id             = post.Id,
                AuthorId       = post.User.Id,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorName     = post.User.UserName,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Title          = post.Title,
                PostReplies    = post.PostReplies.Select(x => new PostReplyModel
                {
                    AuthorId       = x.User.Id,
                    AuthorImageUrl = x.User.ProfileImageUrl,
                    AuthorName     = x.User.UserName,
                    AuthorRating   = x.User.Rating,
                    Id             = x.Id,
                    Created        = x.Created,
                    PostId         = x.Post.Id,
                    ReplyContent   = x.Content
                })
            };

            return(View(model));
        }
コード例 #6
0
        public IActionResult Index(string sortOrder, string searchString, int?pageIndex)
        {
            ViewData["NameSortParm"]  = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
            ViewData["DateSortParm"]  = sortOrder == "Date" ? "Date_desc" : "Date";
            ViewData["CurrentFilter"] = searchString;

            var posts = _postService.GetFilteredPost(sortOrder, searchString).Where(p => p.Status == true)
                        .Select(post => new PostViewModel
            {
                Id           = post.Id,
                Title        = post.Title,
                Content      = post.Content,
                Created      = post.Created,
                AuthorId     = post.User.Id,
                AuthorName   = post.User.UserName,
                AuthorRating = post.User.Rating,
                Status       = post.Status,
                ImageProfile = post.User.ProfileImageUrl,
                FileUrl      = post.FileUrl,
                NumberRead   = post.NumberRead,
                RepliesCount = post.Replies.Count()
            });
            var model = new PostIndexModel
            {
                ListPosts = posts
            };

            return(View(model));
        }
コード例 #7
0
        public async Task <IActionResult> Index()
        {
            var postList = _context
                           .Posts
                           .Include("Owner")
                           .ToList();

            var postModel = new PostIndexModel();

            foreach (var item in postList)
            {
                var post = new Post
                {
                    Id          = item.Id,
                    Title       = item.Title,
                    BloodType   = item.BloodType,
                    City        = item.City,
                    Category    = item.Category,
                    Description = item.Description,
                    Owner       = item.Owner
                };

                postModel.Posts.Add(post);
            }

            var _currentUser = GetCurrentUser();

            postModel.IsAdmin = _currentUser == null ? false : await _userManager.IsInRoleAsync(_currentUser, "admin");

            postModel.IsDonor = _currentUser == null ? false : _currentUser.IsDonor;

            return(View(postModel));
        }
コード例 #8
0
        public async Task <ActionResult> Post(PostIndexModel model)
        {
            await Search(model);
            await PopulatePostPageAsync(model);

            return(PartialView("Post/_PostResult", model));
        }
コード例 #9
0
        private async Task Search(PostIndexModel model)
        {
            var response = await _blogService.FindAsync(_mapper.Map <PostFindRequest>(model));

            model.Results             = _mapper.Map <List <PostModel> >(response.Results);
            model.Paging.TotalRecords = response.TotalRecords;
        }
コード例 #10
0
ファイル: PostController.cs プロジェクト: optmzer/ForumApp
        public IActionResult Index(int postId)
        {
            var post = _postService.GetPostById(postId);
            // For now it returns NULL as posts do not exist
            // Wonder if there is a way to fix it and return an empty page?
            var replies = BuildPostRepliesModel(post.Replies);

            var model = new PostIndexModel
            {
                Id            = post.Id,
                Title         = post.Title,
                Created       = post.Created.ToLocalTime().ToString("d"),
                Content       = post.Content,
                AuthorId      = post.User.Id,
                AuthorName    = post.User.UserName,
                AuthorImgUrl  = post.User.ProfileImageUrl,
                AuthorRating  = post.User.Rating,
                Forum         = BuildForumListing(post.Forum),
                PostReplies   = replies,
                RepliesCount  = post.Replies.Count(),
                IsAuthorAdmin = IsAuthorAdmin(post.User)
            };

            return(View(model));
        }
コード例 #11
0
        public async Task <ActionResult> Post()
        {
            SetTitle("Bài Viết");
            var model = new PostIndexModel();

            await Search(model);
            await PopulatePostPageAsync(model);

            return(View(model));
        }
コード例 #12
0
        private async Task PopulatePostPageAsync(PostIndexModel model)
        {
            model.Paging.PageClickFunction = "comdy.post.search({0})";
            model.Categories = await _categoryService.GetReferencesAsync();

            foreach (var item in model.Results)
            {
                item.CategoryName = model.Categories.Where(a => a.Id == item.CategoryId).Select(a => a.Name).FirstOrDefault();
            }
            model.PopulateCreatedUser(await _userService.GetReferencesAsync());
        }
コード例 #13
0
ファイル: ShareController.cs プロジェクト: hunghop090/Engnest
 public ActionResult Index(long?id)
 {
     if (id == null)
     {
         return(RedirectToAction("Index", "Login"));
     }
     else
     {
         PostIndexModel model = new PostIndexModel();
         model.Id = id;
         return(View(model));
     }
 }
コード例 #14
0
        //Forum student
        public IActionResult Forum()
        {
            var posts = _postService.GetPostForumStudent()
                        .Select(p => new PostViewModel {
                Id      = p.Id,
                Title   = p.Title,
                Content = p.Content
            });
            var model = new PostIndexModel {
                ListPosts = posts
            };

            return(View(model));
        }
コード例 #15
0
        public async Task <IActionResult> Category([FromRoute] string slug, [FromQuery] int p = 1)
        {
            try
            {
                if (string.IsNullOrEmpty(slug))
                {
                    return(NotFound());
                }

                var category = await _categoryService.GetCategoryAsync(slug.ToLowerInvariant());

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

                var response = await _blogService.SearchPostsAsync(new Data.PostSearchRequest
                {
                    CategoryId = category.Id,
                    PageNumber = p,
                    PageSize   = Common.Settings.PageSize
                });

                var popularPosts = await _blogService.GetPopularPostsAsync();

                var categories = await _categoryService.GetAllCategoriesAsync();

                var model = new PostIndexModel
                {
                    CurrentCategory = category,
                    Results         = response.Results
                };
                model.Paging.PageNumber        = p;
                model.Paging.PageClickUrl      = $"{category.GetUrl()}?p=";
                model.Paging.TotalRecords      = response.TotalRecords;
                model.RightBar.Categories      = categories;
                model.RightBar.Popular         = popularPosts;
                model.RightBar.CurrentCategory = category;

                SetTitle(category.Name, category.GetUrl());

                return(View($"{Common.WebSetting.ThemeId}/Category", model));
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "BlogController > Category");
                return(NotFound());
            }
        }
コード例 #16
0
ファイル: PostController.cs プロジェクト: hunghop090/Engnest
 public ActionResult Index(long?id, long?CommentId)
 {
     if (id == null && CommentId == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         PostIndexModel model = new PostIndexModel();
         model.Id        = id;
         model.CommentId = CommentId;
         model.Profile   = Mapper.Map <ProfileModel>(userLogin);
         return(View(model));
     }
 }
コード例 #17
0
        //End Comment
        public IActionResult Searching(string sortOrder, string searchQuery)
        {
            ViewData["FilterFunction"] = searchQuery;
            var posts = _postService.GetFilteredPost(sortOrder, searchQuery)
                        .Select(p => new PostViewModel {
                Id      = p.Id,
                Title   = p.Title,
                Content = p.Content,
                Created = p.Created
            });
            var model = new PostIndexModel {
                SearchQuery = posts
            };

            return(View(model));
        }
コード例 #18
0
        public IActionResult Index(int id)
        {
            var post = _postService.GetById(id);

            var model = new PostIndexModel
            {
                Id          = post.Id,
                Title       = post.Title,
                PostContent = _postFormatter.FormatContent(post.Content),
                AuthorName  = post.User.FirstName + " " + post.User.LastName,
                Created     = post.Created,
                SectionName = post.Section.Title,
                SectionId   = post.Section.Id
            };

            return(View(model));
        }
コード例 #19
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = BuildReplies(post.Replies);
            var model   = new PostIndexModel
            {
                Id         = post.Id,
                Title      = post.Title,
                AuthorId   = post.Instructor.Id,
                AuthorName = post.Instructor.Name,
                ImgUrl     = post.Instructor.ImageUrl,
                Body       = post.Body,
                Replies    = replies,
                Created    = post.Created
            };

            return(View(model));
        }
コード例 #20
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = BuilPostReplies(post.Replies);
            var model   = new PostIndexModel {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies
            };

            return(View(model));
        }
コード例 #21
0
        public void Index_GivenOnePost_ReturnedModelHasItsPropertiesFilled()
        {
            //Arrange
            var expectedUserData = new ApplicationUser()
            {
                Created = DateTime.Now, Id = "1", ProfileImageUrl = "realUrl", UserName = "******", Rating = 1
            };
            var expectedForumData = new Forum()
            {
                Id = 1, Title = "Forum Title"
            };
            var expectedPostData  = new Post();     //needed to declare Post to be able to put a reference in reply
            var expectedReplyData = new List <PostReply>()
            {
                new PostReply()
                {
                    User = expectedUserData, Content = "Reply Content", Created = DateTime.Now, Forum = expectedForumData, Id = 1, Post = expectedPostData
                }
            };

            expectedPostData = new Post()
            {
                Content = "Post Content", Created = DateTime.Now, Id = 1, Title = "Returned Post", Replies = expectedReplyData, User = expectedUserData, Forum = expectedForumData
            };
            _postService.GetById(1).Returns(expectedPostData);

            //Act
            ViewResult     view           = (ViewResult)_controller.Index(1);
            PostIndexModel actualPostData = (PostIndexModel)view.Model;

            //Assert
            Assert.Equal(expectedForumData.Id, actualPostData.ForumId);
            Assert.Equal(expectedForumData.Title, actualPostData.ForumName);
            Assert.Equal(expectedUserData.Id, actualPostData.AuthorId.ToString());
            Assert.Equal(expectedUserData.UserName, actualPostData.AuthorName);
            Assert.Equal(expectedUserData.ProfileImageUrl, actualPostData.AuthorImageUrl);
            Assert.Equal(expectedUserData.Rating, actualPostData.AuthorRating);
            Assert.Equal(expectedPostData.Id, actualPostData.Id);
            Assert.Equal(expectedPostData.Title, actualPostData.Title);
            Assert.Equal(expectedPostData.Created, actualPostData.Created);
            Assert.Equal(expectedPostData.Content, actualPostData.Content);
            Assert.NotEmpty(actualPostData.Replies);
        }
コード例 #22
0
        public IActionResult Index(int id)
        {
            var post = _postService.GetById(id);

            if (post.Replies.Any())
            {
                foreach (var reply in post.Replies)
                {
                    if (reply.Content != null)
                    {
                        foreach (Match item in Regex.Matches(reply.Content, @"(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?"))
                        {
                            string LinkInHtml = ConvertTextUrlToLink(item.Value);
                            reply.Content.Replace(item.Value, LinkInHtml);
                        }
                    }
                }
            }

            var replies = BuildPostReplies(post.Replies);
            var model   = new PostIndexModel
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorName     = post.User.UserName,
                AutorRating    = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies,
                IsAuthorActive = post.User.IsActive,
                IsAuthorAdmin  = IsAuthorAdmin(post.User),
                ForumId        = post.Forum.Id,
                ForumName      = post.Forum.Title
            };

            if (post.ImageUrl != "" && post.ImageUrl != null)
            {
                model.PostImageUrl = post.ImageUrl;
            }
            return(View(model));
        }
コード例 #23
0
        public IActionResult Index(int id)
        {
            var m_post = m_postService.GetById(id);

            var m_replies = BuildPostReplies(m_post.Replies);

            var m_model = new PostIndexModel
            {
                Id             = m_post.Id,
                Title          = m_post.Title,
                AuthorId       = m_post.User.Id,
                AuthorName     = m_post.User.UserName,
                AuthorImageUrl = m_post.User.ProfileImageUrl,
                Created        = m_post.Created,
                MediaCaption   = m_post.Content,
                Replies        = m_replies
            };

            return(View(m_model));
        }
コード例 #24
0
        // GET: Post
        public ActionResult Index(int id)
        {
            var posts   = _postRepositories.GetById(id);
            var replies = BuildPostReplies(posts.Replies);
            var model   = new PostIndexModel
            {
                Id           = posts.Id,
                Title        = posts.Title,
                AuthorId     = posts.User.Id,
                AuthorName   = posts.User.UserName,
                AuthorRating = posts.User.Rating,
                DateCreated  = posts.Created,
                PostContent  = posts.Content,
                Replies      = replies,
                ForumId      = posts.Forum.Id,
                ForumName    = posts.Forum.Title,
                IsAdmin      = IsAdmin(posts.User)
            };

            return(View(model));
        }
コード例 #25
0
        public ActionResult Search(String word)
        {
            var post   = this.User;
            var token  = post.Claims.FirstOrDefault(p => p.Type == ClaimTypes.Sid).Value;
            var UserId = post.Claims.FirstOrDefault(p => p.Type == ClaimTypes.NameIdentifier).Value;
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Authorization", "Bearer " + token);

            var model = new PostIndexModel();

            model.UserId = Convert.ToInt32(UserId);
            var getUri = string.Format("{0}/{1}", apiUrl, "post/search?Word=" + word);

            model.Posts = _apiService.GetMethod <List <PostViewModel> >(getUri, headers);
            if (model.Posts == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #26
0
ファイル: PostsController.cs プロジェクト: bushjm23/saidwhat
        public ActionResult Index(uint page = 1, uint pageSize = 25)
        {
            uint total;
            var  posts = Post.Find(page, pageSize, out total);

            var model = new PostIndexModel()
            {
                Page         = page,
                PageSize     = pageSize,
                TotalResults = total,
                Posts        = posts
            };

            if (!IsJsonRequest)
            {
                return(View("index", model));
            }
            else
            {
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #27
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = GetPostReplies(post).OrderBy(reply => reply.Date);

            var model = new PostIndexModel {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorRating   = post.User.Rating,
                IsAuthorAdmin  = IsAuthorAdmin(post.User),
                Date           = post.Created,
                PostContent    = _postFormatter.Prettify(post.Content),
                Replies        = replies,
                ForumId        = post.Forum.Id,
                ForumName      = post.Forum.Title
            };

            return(View(model));
        }
コード例 #28
0
        public IActionResult Index(int id)
        {
            var post    = this.postService.GetById(id);
            var replies = this.BuildPostReplies(post.Replies);
            var model   = new PostIndexModel()
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileUrl,
                AuthorRating   = post.User.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies,
                ForumName      = post.Forum.Title,
                ForumId        = post.Forum.Id,
                IsAuthorAdmin  = this.IsAuthorAdmin(post.User)
            };

            return(View(model));
        }
コード例 #29
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = BuildPostReplies(post.Replies);

            var model = new PostIndexModel
            {
                Id             = post.PostId,
                Title          = post.Title,
                AuthorId       = post.ApplicationUsers.Id,
                AuthorName     = post.ApplicationUsers.UserName,
                AuthorImageUrl = post.ApplicationUsers.ProfileImageUrl,
                AuthorRating   = post.ApplicationUsers.Rating,
                Created        = post.Created,
                PostContent    = post.Content,
                Replies        = replies,
                ForumId        = post.Forum.ForumId,
                ForumName      = post.Forum.Title,
                IsAuthorAdmin  = IsAuthorAdmin(post.ApplicationUsers)
            };

            return(View(model));
        }
コード例 #30
0
        public IActionResult Index(int id)
        {
            var post    = _postService.getById(id);
            var replies = BuildPostReplies(post.replies);

            var model = new PostIndexModel
            {
                id             = post.id,
                title          = post.title,
                authorId       = post.user.Id,
                authorName     = post.user.UserName,
                authorImageUrl = post.user.profileImageUrl,
                authorRathing  = post.user.rating,
                created        = post.created,
                content        = post.content,
                replies        = replies,
                forumId        = post.forum.id,
                forumName      = post.forum.title,
                isAuthorAdmin  = isAuthorAdmin(post.user)
            };

            return(View(model));
        }