コード例 #1
0
        public ActionResult Index(string category = null, int page = 1)
        {
            var pageOffset = (page - 1) * PageSize;
            int postCount;
            ICollection <Post> posts;

            if (!string.IsNullOrEmpty(category))
            {
                posts     = postService.GetPostsByCategory(category, pageOffset, PageSize);
                postCount = postService.Count(category);
            }
            else
            {
                posts     = postService.GetPosts(pageOffset, PageSize);
                postCount = postService.Count();
            }

            var postDtos = posts.Select(post => new PostDto
            {
                Id    = post.Id,
                Title = post.Title,
                Body  = post.Body,
                CreationDateTimeUtc = post.CreationDateTimeUtc
            }).ToList();
            var totalPages    = (int)Math.Ceiling(postCount / (double)PageSize);
            var pageViewModel = new PostPageViewModel
            {
                CurrentPage  = page,
                TotalPages   = totalPages,
                CategoryName = category,
                Posts        = postDtos
            };

            return(View(pageViewModel));
        }
コード例 #2
0
        public async Task<IActionResult> Index(string sort, int page)
        {
            if (sort != null)
            {
                var sortedPosts = await this.postsService.SortPostsByCategoryAsync(sort);

                var sortedPostsViewModel = new PostPageViewModel
                {
                    PostsPerPage = ServicesConstants.PostsCountPerPage,
                    CurrentPage = page,
                    Posts = sortedPosts,
                };

                return this.View(sortedPostsViewModel);
            }
            else
            {
                var allPosts = await this.postsService.GetAllPostsAsync();

                var allPostsViewModel = new PostPageViewModel
                {
                    PostsPerPage = ServicesConstants.PostsCountPerPage,
                    CurrentPage = page,
                    Posts = allPosts,
                };

                return this.View(allPostsViewModel);
            }
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: wangscript007/iBlog
        public ActionResult PostPage(string year, string month, string url, string status)
        {
            var allPosts = this.GetPosts();
            var current  = allPosts.SingleOrDefault(p => p.Url == url && p.EntryType == 1);

            if (current == null)
            {
                throw new UrlNotFoundException("Unable to find a post w/ the url {0} for the month {1} and year {2}", url, month, year);
            }

            if (!Request.IsAuthenticated && status == "comment-successed")
            {
                var recentPost = this.postService.GetPostByUrl(url, 1);
                current.Comments = recentPost.Comments;
            }

            var index = allPosts.IndexOf(current);
            var model = new PostPageViewModel
            {
                Post          = current,
                PreviousPost  = index == 0 || index < 0 ? null : allPosts[index - 1],
                NextPost      = index == (allPosts.Count - 1) || index < 0 ? null : allPosts[index + 1],
                UserCanEdit   = Request.IsAuthenticated && (current.UserID == GetUserId() || User.IsInRole("SuperAdmin")),
                BlogName      = this.settingService.BlogName,
                BlogCaption   = this.settingService.BlogCaption,
                CommentEntity = this.GetCommentEntity()
            };

            return(this.View(model));
        }
コード例 #4
0
 public PostPage(MPost post)
 {
     InitializeComponent();
     BindingContext = PostPageVM = new PostPageViewModel {
         Post = post
     };
 }
コード例 #5
0
        public async Task<IActionResult> Search(SearchViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.RedirectToAction("Index");
            }

            var posts = await this.postsService.GetPostsBySearchAsync(inputModel);

            if (posts == null)
            {
                var empty = Enumerable.Empty<PostDetailsViewModel>();

                var emptyPostsViewModel = new PostPageViewModel
                {
                    PostsPerPage = ServicesConstants.PostsCountPerPage,
                    CurrentPage = ServicesConstants.PostsDefaultPage,
                    Posts = empty,
                };

                return this.View("Index", emptyPostsViewModel);
            }

            var searchPostsViewModel = new PostPageViewModel
            {
                PostsPerPage = ServicesConstants.PostsCountPerPage,
                CurrentPage = ServicesConstants.PostsDefaultPage,
                Posts = posts,
            };

            return this.View("Index", searchPostsViewModel);
        }
コード例 #6
0
        public IActionResult Post(int post_id)
        {
            Post          post      = _postLogic.GetPostById(post_id);
            PostViewModel postModel = new PostViewModel()
            {
                Title        = post.Title,
                Content      = post.Content,
                PostId       = post.PostId,
                AuraAmount   = post.Aura.Amount,
                PostDate     = post.PostDate,
                UserId       = post.User.UserId,
                UserName     = post.User.Name,
                CategoryId   = post.Category.CategoryId,
                CategoryName = post.Category.Name,
            };
            PostPageViewModel model = new PostPageViewModel()
            {
                Categories = _categoryLogic.GetAll()
                             .Select(c => new CategoryViewModel {
                    Id = c.CategoryId, Name = c.Name
                }).ToList(),
                Post = postModel,
            };

            return(View(model));
        }
コード例 #7
0
        public ActionResult Index(PostPageViewModel currentPage, int year, string slug = "")
        {
            //we want to allow just /year being hit, and redirected to blog home
            if (string.IsNullOrWhiteSpace(slug))
            {
                return(RedirectToAction("Index", "Blog"));
            }

            //try get the post from memcache first
            var post = MemoryCache.GetPost(year, slug);

            if (post != null)
            {
                currentPage.Slug       = post.Slug;
                currentPage.Title      = post.Title;
                currentPage.PostedTime = post.PostedTime;
                currentPage.BodyHtml   = post.BodyHtml;
                currentPage.ReadTime   = post.ReadTime;
                currentPage.Categories = post.Categories;
                currentPage.AuthorName = SettingsCache.GetAuthor();

                //replace defaults in base page
                currentPage.DontIndexPage = post.DontIndexPost;
                currentPage.WindowTitle   = post.Title;
                if (!string.IsNullOrWhiteSpace(post.MetaDescPost))
                {
                    currentPage.MetaDescription = post.MetaDescPost;
                }

                return(View("Post", currentPage));
            }

            return(RedirectToAction("NotFound", "Error"));
        }
コード例 #8
0
 public AddSimCommentPage(PostPageViewModel postPageVM)
 {
     InitializeComponent();
     BindingContext    = viewModel = new SelectSimViewModel(5);
     postPageViewModel = postPageVM;
     Title             = "Sim của tôi";
     Initialize().GetAwaiter();
 }
コード例 #9
0
        public IActionResult Details(Guid id)
        {
            var forum = _context.Forums.SingleOrDefault(f => f.Id == id);
            var post = _context.Posts.Where(p => p.ForumID == id).ToList();

            var viewmodel = new PostPageViewModel
            {
                Post = post,
                Forum = forum
            };
            return View(viewmodel);
        }
コード例 #10
0
        public async void Init()
        {
            this.BindingContext = viewModel = new PostPageViewModel();

            //set mac dinh ngay cam ket la ngay hien tai
            radDateTimePicker_From.DefaultDisplayDate = DateTime.Now;
            radDateTimePicker_To.DefaultDisplayDate   = DateTime.Now;

            SegmentedLoaiHinh.ItemsSource = new string[] { Language.can_ban, Language.cho_thue, Language.can_mua, Language.can_thue };
            await CrossMedia.Current.Initialize();

            await viewModel.GetProjects();
        }
コード例 #11
0
        public IViewComponentResult Invoke(int page)
        {
            var posts = this.postsService.GetFourLatestPostsAsync()
                        .GetAwaiter()
                        .GetResult();

            var postsViewModel = new PostPageViewModel
            {
                PostsPerPage = ServicesConstants.PostsCountPerPage,
                CurrentPage  = page,
                SidebarPosts = posts,
            };

            return(this.View(postsViewModel));
        }
コード例 #12
0
        public async Task <IActionResult> Search(SearchViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View("Error404"));
            }

            var programs = await this.searchesService.GetProgramsBySearchTextAsync(inputModel);

            if (programs != null)
            {
                return(this.View("~/Views/Programs/Index.cshtml", programs));
            }

            var products = await this.searchesService.GetProductsBySearchTextAsync(inputModel);

            if (products != null)
            {
                var productsPageViewModel = new ProductsPageViewModel
                {
                    ProductPerPage = ServicesConstants.PostsCountPerPage,
                    Products       = products,
                };

                return(this.View("~/Views/Products/Index.cshtml", productsPageViewModel));
            }

            var posts = await this.postsService.GetPostsBySearchAsync(inputModel);

            if (posts != null)
            {
                var postPageViewModel = new PostPageViewModel
                {
                    PostsPerPage = ServicesConstants.PostsCountPerPage,
                    Posts        = posts,
                };

                return(this.View("~/Views/Posts/Index.cshtml", postPageViewModel));
            }

            return(this.View("Error404"));
        }
コード例 #13
0
        public HttpResponseMessage GetPostFileDetails(int fileId, int repositoryId)
        {
            Func <DM.File, bool> fileByFileIdAndUserIdFilter = f => f.FileId == fileId && f.CreatedBy == this.user.UserId && (f.isDeleted == null || f.isDeleted == false);

            DM.File file = fileService.GetFiles(fileByFileIdAndUserIdFilter).FirstOrDefault();
            if (file == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.FileNotFound));
            }

            bool   isAdmin       = this.user.UserRoles.Any(ur => ur.Role.Name.Equals(Roles.Administrator.ToString(), StringComparison.OrdinalIgnoreCase));
            string fileExtension = Path.GetExtension(file.Name).Replace(".", string.Empty);
            IEnumerable <DM.Repository> repositoryList = this.repositoryService.GetRepositoriesByRoleAndFileExtension(isAdmin, fileExtension);

            if (repositoryList.FirstOrDefault(r => r.RepositoryId == repositoryId) == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.Repository_Not_Found));
            }

            PostPageViewModel postPageViewModel = new PostPageViewModel();

            postPageViewModel.FileId       = fileId;
            postPageViewModel.FileName     = file.Name;
            postPageViewModel.RepositoryId = repositoryId;
            foreach (DM.Repository dmRepository in repositoryList)
            {
                Models.Repository repository = new Models.Repository()
                {
                    Id               = dmRepository.RepositoryId,
                    Name             = dmRepository.Name,
                    BaseRepositoryId = dmRepository.BaseRepositoryId,
                    IsImpersonating  = dmRepository.IsImpersonating.HasValue && dmRepository.IsImpersonating.Value == true,
                    UserAgreement    = dmRepository.UserAgreement
                };

                postPageViewModel.RepositoryList.Add(repository);
            }

            return(Request.CreateResponse <PostPageViewModel>(HttpStatusCode.OK, postPageViewModel));
        }
コード例 #14
0
        public PostPage()
        {
            InitializeComponent();

            BindingContext = new PostPageViewModel();
        }
コード例 #15
0
 public PostPage()
 {
     _postPageViewModel = new PostPageViewModel();
     this.InitializeComponent();
     Windows.UI.ViewManagement.StatusBar.GetForCurrentView().BackgroundColor = Color.FromArgb(1, 78, 101, 135);
 }
コード例 #16
0
 public PostPage(string template)
 {
     InitializeComponent();
     DataContext = new PostPageViewModel(template);
 }
コード例 #17
0
 public PostPage(Post post)
 {
     InitializeComponent();
     BindingContext = viewModel = new PostPageViewModel(post);
     Init();
 }
コード例 #18
0
 //in a perfect world we wouldn't need this. Unfortunately the way Disqus handles urls sucks
 //so we need to account for it by redirecting "their" format to our format.
 public ActionResult Redirect(PostPageViewModel currentPage, string s, int y)
 {
     return(RedirectToAction("Index", new { year = y, slug = s }));
 }