Beispiel #1
0
        public async Task <IViewComponentResult> InvokeAsync(long blogId, bool IsEditable)
        {
            var results = new List <DetailedSectionVm>();

            var blog     = blogService.GetBlogWithId(blogId);
            var sectsIds = blogService.SectionsOfBlog(blogId);


            foreach (var sectId in sectsIds)
            {
                var s     = sectionsService.GetSectionWithId(sectId);
                var posts = sectionsService.TopNPosts(sectId, 5);

                var result = new DetailedSectionVm()
                {
                    Name            = s.Name,
                    Id              = s.Id,
                    PhotoId         = s.PhotoId,
                    IsSystemCreated = s.IsSystemCreated,
                    Posts           = posts,
                    BlogId          = blogId,
                    OwnerId         = blog.UserId,
                    OwnerUsername   = userInfoService.GetUserWithId(blog.UserId).Username
                };

                results.Add(result);
            }

            if (IsEditable)
            {
                return(View("Editable", new MainScreenSectionRow()
                {
                    DetailedSections = results
                }));
            }
            else
            {
                return(View("Default", new MainScreenSectionRow()
                {
                    DetailedSections = results
                }));
            }
        }
Beispiel #2
0
        private async Task <IEnumerable <Posts> > FillPosts(long sectId)
        {
            var topPosts = sectionsService.TopNPosts(sectId, 3);

            return(topPosts);
        }
Beispiel #3
0
        private HomeResultsVm GetResultsForUser(Users user)
        {
            if (user == null)
            {
                return(new HomeResultsVm()
                {
                    BlogResults = new List <HomeBlogVm>(),
                    PostResults = new List <HomePostVm>(),
                    SectionResults = new List <HomeSectionVm>()
                });
            }

            var postResults = new List <HomePostVm>();
            var blogResults = new List <HomeBlogVm>();
            var sectResults = new List <HomeSectionVm>();

            var blogs = userBlogService.GetBlogsForUser(user.Id)
                        .OrderByDescending(b => b.Id) // ca sa selectam din cele mai noi
                        .Take(randomizer.Next(1, 4)).ToList();

            foreach (var blog in blogs)
            {
                var sects = blogService.GetSections(blog.Id)
                            .OrderByDescending(s => s.Id)
                            .Take(randomizer.Next(1, 3));
                foreach (var sect in sects)
                {
                    var bestPosts = sectionsService.TopNPosts(sect.Id, randomizer.Next(2, 3));
                    foreach (var post in bestPosts)
                    {
                        postResults.Add(new HomePostVm()
                        {
                            PostId        = post.Id,
                            PostBody      = post.Body,
                            PostTitle     = post.Title,
                            OwnerId       = user.Id,
                            OwnerUsername = user.Username,
                            SectId        = sect.Id,
                            SectTitle     = sect.Name,
                            PhotoId       = post.PhotoId
                        });
                    }

                    sectResults.Add(new HomeSectionVm()
                    {
                        SectId        = sect.Id,
                        SectTitle     = sect.Name,
                        BlogId        = blog.Id,
                        OwnerId       = user.Id,
                        OwnerUsername = user.Username,
                        PhotoId       = sect.PhotoId
                    });
                }

                blogResults.Add(new HomeBlogVm()
                {
                    BlogId        = blog.Id,
                    BlogTitle     = blog.Title,
                    OwnerId       = user.Id,
                    OwnerUsername = user.Username,
                    PhotoId       = blog.PhotoId,
                    Sections      = sects
                });
            }

            return(new HomeResultsVm()
            {
                BlogResults = blogResults,
                PostResults = postResults,
                SectionResults = sectResults
            });
        }