Пример #1
0
        //Returnerar partial View med alla posts som hör till en användares profilsida
        public ActionResult _DisplayPostsPartial(string userId)
        {
            var posts    = new PostDbContext().Posts.Where(p => p.UserId == userId).OrderByDescending(p => p.Id).ToList();
            var authors  = new ProfileDbContext().Profiles.ToList();
            var postList = new List <PostViewModel>();

            foreach (var p in posts)
            {
                var author = authors.FirstOrDefault(a => a.UserId == p.Author_UserId);

                postList.Add(new PostViewModel()
                {
                    Author_UserId   = p.Author_UserId,
                    Author_FullName = string.Concat(author.FirstName, " ", author.LastName),
                    Text            = p.Text,
                    UserId          = p.UserId
                });
            }
            return(PartialView(postList));
        }