Beispiel #1
0
        // GET
        public ActionResult Index()
        {
            AllPostsModel allPosts = new AllPostsModel();

            using (var db = new BlogModels())
            {
                allPosts.AllPosts = db.Posts.Include(p => p.Comments).OrderByDescending(p => p.CreationTime).Take(100).ToArray();
                var allAuthorsId = allPosts.AllPosts.Select(p => p.Author);
                using (var idb = new IdentityDbContext())
                {
                    var allIdentityUsers = from user in idb.Users
                                           where allAuthorsId.Contains(user.Id)
                                           select user;
                    foreach (var post in allPosts.AllPosts)
                    {
                        post.Views++;
                    }

                    allPosts.AllAuthors = allIdentityUsers.ToArray();
                    db.SaveChanges();
                }
            }

            return(View(allPosts));
        }
Beispiel #2
0
        public ActionResult <AllPostsModel> PartOfPosts(string name, int page)
        {
            interfaceOperation = true;
            var result = GetPostsByGroup(name, page + 1, 10);
            var posts  = new AllPostsModel {
                Posts = result.Value.Content, page = result.Value.Page, GroupName = name
            };

            if (posts.Posts.Count() == 0)
            {
                posts.message = "No posts! You can be first.";
            }
            return(View(posts));
        }