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)); }
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); } }
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)); }
public PostPage(MPost post) { InitializeComponent(); BindingContext = PostPageVM = new PostPageViewModel { Post = post }; }
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); }
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)); }
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")); }
public AddSimCommentPage(PostPageViewModel postPageVM) { InitializeComponent(); BindingContext = viewModel = new SelectSimViewModel(5); postPageViewModel = postPageVM; Title = "Sim của tôi"; Initialize().GetAwaiter(); }
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); }
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(); }
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)); }
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")); }
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)); }
public PostPage() { InitializeComponent(); BindingContext = new PostPageViewModel(); }
public PostPage() { _postPageViewModel = new PostPageViewModel(); this.InitializeComponent(); Windows.UI.ViewManagement.StatusBar.GetForCurrentView().BackgroundColor = Color.FromArgb(1, 78, 101, 135); }
public PostPage(string template) { InitializeComponent(); DataContext = new PostPageViewModel(template); }
public PostPage(Post post) { InitializeComponent(); BindingContext = viewModel = new PostPageViewModel(post); Init(); }
//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 })); }