Пример #1
0
        // GET: Post
        public ActionResult Index()
        {
            var userId  = Convert.ToInt32(User.Identity.GetUserId());
            var post    = postManager.GetAll().OrderByDescending(c => c.Id);
            var allPost = post.Where(c => c.UserId == userId);

            return(View(allPost));
        }
Пример #2
0
        // GET: Post
        public ActionResult Index()
        {
            var allPost = _postManager.GetAll();
            var allCat  = _catagoryManager.GetAll();

            List <Post> postList = new List <Post>();

            foreach (var post in allPost)
            {
                var postVM = new Post
                {
                    Id       = post.Id,
                    Title    = post.Title,
                    Details  = post.Details,
                    Tags     = post.Tags,
                    Catagory = allCat.Where(x => x.Id == post.CatagoryId).FirstOrDefault()
                };
                postList.Add(postVM);
            }
            return(View(postList));
            //return Json(new {data = postList}, JsonRequestBehavior.AllowGet);
        }
        public async Task <IReadOnlyList <GetPostOutput> > ListAll()
        {
            var list = await _manager.GetAll();

            return(list.Select(ObjectMapper.Map <GetPostOutput>).ToList());
        }
Пример #4
0
        public ActionResult GetAll()
        {
            var posts = _postManager.GetAll();

            return(Json(posts));
        }
Пример #5
0
        // GET: Posts
        public IActionResult Index()
        {
            var posts  = postManager.GetAll();
            var models = new List <IndexViewModel>();

            foreach (var post in posts)
            {
                IndexViewModel model = new IndexViewModel();
                var            user  = userManager.FindByIdAsync(post.OwnerID).Result;
                model.FullName    = user.FullName;
                model.Avatar      = user.Avatar;
                model.Title       = post.Title;
                model.Description = post.Description;
                model.DateTime    = post.DateTime.ToString();
                model.PostId      = post.Id;
                model.Country     = post.Country;
                model.City        = post.City;
                if (post.Like != null)
                {
                    model.Like = post.Like.TotalCount;
                }
                else
                {
                    model.Like = 0;
                }

                if (post.Rating != null)
                {
                    model.AvgRating        = post.Rating.AverageRating;
                    model.TotalRatingCount = post.Rating.UIDs.Count;
                }
                else
                {
                    model.AvgRating        = 0;
                    model.TotalRatingCount = 0;
                }

                List <string> imagesPath = new List <string>();
                if (post.Images != null)
                {
                    foreach (var image in post.Images)
                    {
                        imagesPath.Add(image.FilePath);
                    }
                    model.ImagePath = imagesPath;
                }
                List <string> videoPath = new List <string>();
                if (post.Videos != null)
                {
                    foreach (var video in post.Videos)
                    {
                        videoPath.Add(video.FilePath);
                    }
                    model.VideoPath = videoPath;
                }
                if (post.Comments != null)
                {
                    foreach (var c in post.Comments)
                    {
                        var c_user = userManager.FindByIdAsync(c.OwnerId).Result;
                        CommentsViewModel commentsView = new CommentsViewModel();
                        commentsView.Avatar      = c_user.Avatar;
                        commentsView.FullName    = c_user.FullName;
                        commentsView.Description = c.Description;
                        commentsView.Id          = c.Id;
                        commentsView.ownerId     = c.OwnerId;
                        model.Comments.Add(commentsView);
                    }
                }
                models.Add(model);
            }
            return(View(models));
        }
Пример #6
0
 public IEnumerable <Post> Get()
 {
     return(_postManager.GetAll());
 }