// GET: Posts
        public ActionResult Index()
        {
            List <PostDetailVM> postsVM = UnitOfWork.PostManager.GetAll()
                                          .OrderByDescending(p => p.Time)
                                          .Select(p => new PostDetailVM()
            {
                PostId     = p.Id,
                Header     = p.Address,
                Text       = p.Text.Substring(0, 500) + "...",
                Time       = p.Time,
                Category   = p.Category.Name,
                WriterName = p.User.UserName,
                CommentsVM = new CommentVM()
                {
                    PostId   = p.Id,
                    Comments = p.Comments.OrderBy(c => c.Time)
                }
            })
                                          .ToList();
            PostIndexVM postIndex = new PostIndexVM()
            {
                Posts      = postsVM,
                Categories = UnitOfWork.CategoryManager.GetAllBind()
            };

            return(View(postIndex));
        }
        public ActionResult UserArticles()
        {
            var userId = System.Web.HttpContext.Current.User.Identity.GetUserId();
            var user   = UnitOfWork.ApplicationUserManager.FindById(userId);

            List <PostDetailVM> postsVM = UnitOfWork.PostManager.GetAll()
                                          .Where(p => p.User.Id == userId)
                                          .OrderByDescending(p => p.Time)
                                          .Select(p => new PostDetailVM()
            {
                PostId     = p.Id,
                Header     = p.Address,
                Text       = p.Text.Substring(0, 500) + "...",
                Time       = p.Time,
                Category   = p.Category.Name,
                WriterName = p.User.UserName,
                CommentsVM = new CommentVM()
                {
                    PostId   = p.Id,
                    Comments = p.Comments.OrderBy(c => c.Time)
                }
            })
                                          .ToList();
            PostIndexVM postIndex = new PostIndexVM()
            {
                Posts      = postsVM,
                Categories = UnitOfWork.CategoryManager.GetAllBind()
            };

            return(View("Index", postIndex));
        }
示例#3
0
        // GET: Posts/Details/5
        public ActionResult Details(int?id)
        {
            var currentUserId = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post post = db.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }


            var model = new PostIndexVM();

            model.Id                   = post.Id;
            model.IsMyPost             = post.ProjectOwner.Id == currentUserId;
            model.Title                = post.Title;
            model.Url                  = post.Url;
            model.ImageUrl             = post.ImageUrl;
            model.Description          = post.Description;
            model.AreMaterialsIncluded = post.AreMaterialsIncluded;



            var bidsQuery = post.Bids.AsQueryable();

            //this isn't my post. then filter the bids shown to be just mine.
            //if (!model.IsMyPost)
            //{
            //    bidsQuery = bidsQuery.Where(x => x.Bidder.Id == currentUserId);
            //}



            model.Bids = bidsQuery.Select(b => new BidIndexVM
            {
                PostId = b.Post.Id,
                BidId  = b.Id,
                Amount = b.Amount,
                ProjectFinishByDate = b.ProjectFinishByDate
            }).ToList();

            return(View(model));
        }
示例#4
0
        public ActionResult Index()
        {
            PostIndexVM          model = new PostIndexVM();
            PostsRepository      repo  = new PostsRepository();
            SubRedditsRepository subRedditsRepository = new SubRedditsRepository();

            model.Posts = repo.GetAll(p => p.IsApproved == true).OrderByDescending(a => a.Rating).ToList();
            model.TrendingSubReddits = subRedditsRepository.GetAll(null);
            if (AuthManager.LoggedUser != null)
            {
                model.SubReddits = subRedditsRepository.GetAll(null)
                                   .Where(x => x.SubscribedUsers.Any(b => b.Id == AuthManager.LoggedUser.Id)).OrderByDescending(c => c.Id).ToList();
            }
            else
            {
                model.SubReddits = subRedditsRepository.GetAll(null);
            }
            return(View(model));
        }
示例#5
0
        public IActionResult Index(int id)
        {
            Post post    = _postService.GetById(id);
            var  replies = _mapper.Map <IEnumerable <PostReplyVM> >(post.Replies);
            var  vm      = new PostIndexVM()
            {
                Id             = post.Id,
                DatePosted     = post.CreatedAt,
                Title          = post.Title,
                AuthorId       = post.Author.Id,
                AuthorImageUrl = post.Author.ProfileImage,
                AuthorName     = post.Author.UserName,
                AuthorRating   = post.Author.Rating,
                Content        = post.Content,
                Replies        = replies
            };

            return(View(vm));
        }
示例#6
0
        public IActionResult Index(int id)
        {
            var post    = _postService.GetById(id);
            var replies = GetPostReplies(post).OrderBy(reply => reply.Date);

            var model = new PostIndexVM
            {
                Id             = post.Id,
                Title          = post.Title,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.UserImage,
                AuthorRating   = post.User.Rating,
                IsAuthorAdmin  = IsAuthorAdmin(post.User),
                Date           = post.DateCreated,
                PostContent    = _postFormatter.Beautify(post.Content),
                Replies        = (IEnumerable <ReplyVM>)replies,
                ForumId        = post.Forum.Id,
                ForumName      = post.Forum.Title
            };

            return(View(model));
        }