public async Task <IActionResult> PostAsync(int id, int commentId = 0, int parentCommentId = 0) { if (id < 1) { return(RedirectToAction("Index")); } var model = new PostDetailViewModel { Id = id, Post = (await _postService.PostAsync(id)), NestedModel = await BuildNestedModel(), Comments = await _commentService.CommentsByPostIdAsync(id) }; model.CommentId = commentId; model.ParentCommentId = parentCommentId; if (parentCommentId > 0) { model.CommentText = await _commentService.TextEditNestedComment(commentId, CurrentUserId); model.CommentedCommentText = await _commentService.TextEditComment(parentCommentId); } else { if (commentId > 0) { model.CommentText = await _commentService.TextEditComment(commentId, CurrentUserId); } } return(View(model)); }
public async Task <IActionResult> Post(int postId) { try { var post = await _postRepo.GetPost(postId); //var comments = await _commentRepo.GetComments(postId); PaginationParam relPgParam = new PaginationParam() { PageIndex = 1, Limit = 4, SortColoumn = "CreatedAt" }; var relatedPosts = await _postRepo.GetPublishedPostsByCategory(relPgParam, post.CategoryId); const int LIMIT = 4; var topStories = await _postRepo.GetPublishedPostsByClaps(LIMIT); var postDetailViewModel = new PostDetailViewModel() { Post = post, RelatedPosts = relatedPosts.Source, TopStories = topStories }; return(View(postDetailViewModel)); } catch { return(View()); } }
// GET: Posts/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var model = new PostDetailViewModel(); var getpost = await _context.Post .Include(p => p.User) .Include(p => p.Game) .Where(p => p.PostId == id).FirstOrDefaultAsync(); model.Post = getpost; var GroupedComment = await _context.Comment .Include(p => p.Post) .Include(p => p.User) .Where(p => p.PostId == id) .ToListAsync(); model.GroupedComments = GroupedComment; //GET USER ApplicationUser user = await GetCurrentUserAsync(); model.User = user; return(View(model)); }
}//回复评论 public ActionResult PostReplyShow(int id)//显示回复 { var msr = (from n in db.PostReply join m in db.PostComment on n.PostComment_id equals m.PostComment_id join q in db.UserInfo on n.User_id equals q.User_id where n.PostComment_id == id select new PostReplyViewModel { PostReply_id = n.PostReply_id, PostComment_id = m.PostComment_id, ReplyContent = n.PostReply_content, Addtime = (DateTime)n.Addtime, User_id = (int)n.User_id, User_name = q.User_name, User_img = q.User_img, }); var reply = (from m in msr.Where(p => p.PostComment_id == id).OrderByDescending(p => p.Addtime) select m).Take(3); var reply1 = (from m in msr.Where(p => p.PostComment_id == id).OrderByDescending(p => p.Addtime) select m); var postreply = new PostDetailViewModel { post_reply = reply, post_reply1 = reply1, }; return(PartialView(postreply)); }
public IActionResult Details(int?id) { var post = _context.Posts.Include(news => news.PostCategories).ThenInclude(c => c.Category).Include(tag => tag.PostTags).ThenInclude(pt => pt.Tag).Include(u => u.AppUser).FirstOrDefault(pt => pt.Id == id); if (post == null) { return(View("NotFound")); } var pId = post.PostCategories.Select(pn => pn.CategoryId).FirstOrDefault(); ViewData["relatedPost"] = _context.Posts.Where(n => n.PostCategories.Any(pc => pc.CategoryId == pId)).Take(3).ToList(); var userId = _userManager.GetUserId(User); var user = _context.Users.Find(userId); var Comments = _context.Comments.Include(p => p.AppUser).Where(d => d.PostId == post.Id).ToList(); ViewData["latest"] = _context.Posts.Include(l => l.PostCategories).ThenInclude(c => c.Category).Include(tag => tag.PostTags).ThenInclude(pt => pt.Tag).Include(u => u.AppUser).ToList().OrderByDescending(n => n.CreatedDate).Take(5); var model = new PostDetailViewModel { Post = post, ListComments = Comments, AppUser = user }; return(View(model)); }
public async Task <IActionResult> EditPost(PostDetailViewModel model) { if (model == null) { ShowAlertDanger("Could not edit empty post."); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { var post = await _newsService.EditPostAsync(model.Post, model.Publish); if (model.Publish) { return(await SendEmailJobAsync(GetJobParameters(post))); } else { ShowAlertSuccess($"Updated Post \"{post.Title}\"!"); return(RedirectToAction(nameof(Index))); } } model.Action = nameof(CreatePost); model.Categories = new SelectList(await _newsService.GetAllCategoriesAsync(), "Id", "Name"); return(View("PostDetail", model)); }
// Attēlo rakstu ar komentāriem // Funkcija FO.01, FO.10 private ActionResult CreatePostDetailsView(int?id, Comments comment) { Posts posts = db.Posts.Find(id); posts.Comments = db.Comments.Where(c => c.PostID == id).ToList(); if (comment == null) { comment = new Comments { PostID = (int)id }; } PostDetailViewModel post = new PostDetailViewModel { Comments = posts.Comments, Comment = comment, Post = posts, Date = posts.Updated ?? posts.Created }; if (posts == null) { return(HttpNotFound()); } return(View("Details", post)); }
public ActionResult ShowPostDetail(int postId, String currentUserId, int skip, int take) { var postService = this.Service <IPostService>(); Post post = null; ResponseModel <PostDetailViewModel> response = null; try { post = postService.GetPostById(postId); PostOveralViewModel overal = Mapper.Map <PostOveralViewModel>(post); PreparePostOveralData(overal, currentUserId); PostDetailViewModel result = PreparePostDetailData(overal, skip, take); response = new ResponseModel <PostDetailViewModel>(true, "Chi tiết bài viết:", null, result); } catch (Exception) { response = ResponseModel <PostDetailViewModel> .CreateErrorResponse("Tải bài viết thất bại!", systemError); } return(Json(response)); }
// GET: Posts/Details/5 public ActionResult Details(int?id) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //Posts posts = db.Posts.Find(id); //if (posts == null) //{ // return HttpNotFound(); //} //return View(posts); BlogPosts posts = db.BlogPosts.Find(id); var qPict = db.BlogPicts.Where(q => q.PostFK == id).ToList(); var viewModel = new PostDetailViewModel { ID = posts.ID, PostTitle = posts.PostTitle, PostAuthor = posts.PostAuthor, PostTags = posts.PostTags, PostText = posts.PostText, TitlePic = posts.TitlePic, EditDate = posts.EditDate, BlogPicts = qPict, }; return(View(viewModel)); }
public IActionResult Add(PostDetailViewModel vm) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var user = _context.Users.Single(u => u.Id == userId); var comment = vm.Comment; var id = vm.Id; if (ModelState.IsValid) { //_context.Add(comment); // _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } var newcomment = new Comment { PostId = id, CContent = vm.Comment, DateComment = DateTime.Now, AppUser = user }; _context.Comments.Add(newcomment); _context.SaveChanges(); return(RedirectToAction("Details", "Posts", new { id = id })); }
public PostDetailPage(PostViewModel viewModel) { InitializeComponent(); var pageService = new PageService(); BindingContext = new PostDetailViewModel(viewModel ?? new PostViewModel(), pageService); }
public async Task <IActionResult> Index(int id) { PostDetailViewModel model = new PostDetailViewModel(); model.PostId = id; model.Post = await _postsService.GetPost(id); return(View(model)); }
public async Task <IActionResult> Detail(string id) { var post = this._postService.GetById(id); var employer = _employerService.GetAll().Where(e => e.Id == post.EmployerId).First(); var user = _userManager.Users.Where(u => u.Id == employer.UserId).First(); var employerModel = EmployerMapper.MapOne(employer, user); var viewModel = new PostDetailViewModel(post, employerModel); return(View(viewModel)); }
public IActionResult Details(int id) { List <Post> posts = repository.getPosts(id); PostDetailViewModel model = new PostDetailViewModel { posts = posts, blogName = repository.getBloggNameById(id), }; return(View(model)); }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { var img = DataContext as ImgurImage; if (img == null) { return; } dataContext = MainListViewModel.SharedInstance.PostDetailViewModels[img]; DataContext = dataContext; }
public async Task <IActionResult> CreatePost() { var viewModel = new PostDetailViewModel { Action = nameof(CreatePost), Categories = new SelectList(await _newsService.GetAllCategoriesAsync(), "Id", "Name") }; return(View("PostDetail", viewModel)); }
public ActionResult Edit(int Post_Id) { ViewBag.CBXMenuItem = (from s in db.Cs_Menu_item where s.Item_Type.Equals("SP") select s).ToList(); var obj = db.CS_Post_Info.Where(t => t.Post_Id == Post_Id); if (obj.Count() > 0) { var slides = from s in db.CS_Post_Slides where s.Post_Id == Post_Id select s; PostDetailViewModel objView = new PostDetailViewModel(obj.First(), slides.ToList()); return(View(objView)); } return(RedirectToRoute("BaiVietMVC/index")); }
public PostDetailPage() { InitializeComponent(); Post = new Post { About = "Post About 1 hardcoded", Content = "This is a post content description hardcoded." }; viewModel = new PostDetailViewModel(Post); BindingContext = viewModel; }
public async Task <ActionResult> PostDetail(string id) { Post post = await _context.Posts.FindAsync(id); PostDetailViewModel postdet = new PostDetailViewModel(); if (post != null) { postdet.Description = post.Description; postdet.Title = post.Title; } return(View(postdet)); }
public async Task <IActionResult> Detail(string slug) { var post = await _postService.GetPost(slug); if (post == null) { return(NotFound()); } // TODO: Check post's status against user role i.e.: Unauthenticated should not see Drafts or Pending posts return(View( PostDetailViewModel.FromModel(post))); }
public IActionResult AddComment(PostDetailViewModel vm) { if (!ModelState.IsValid || vm.Comment == null) { return(BadRequest()); } if (_posts.AddNewComment(vm.PostId, vm.Comment)) { return(RedirectToAction("Detail", "Post", new { @id = vm.PostId })); } return(BadRequest()); }
public ActionResult AddComment(PostDetailViewModel postModel, FormCollection values) { postModel.Comment.Created = DateTime.Now; postModel.Comment.UserID = User.Identity.GetUserId(); if (ModelState.IsValid) { using (var db = new ApplicationDbContext()) { db.Comments.Add(postModel.Comment); db.SaveChanges(); } } return(CreatePostDetailsView(postModel.Comment.PostID, postModel.Comment)); }
private void Posts_ItemTapped(object sender, ItemTappedEventArgs e) { if (e.Item == null) { return; } if (sender is ListView lv) { lv.SelectedItem = null; } var vmTo = new PostDetailViewModel(e.Item); var page = new PostDetailPage(vmTo); Navigation.PushAsync(page); }
public IActionResult Detail(int postId) { var model = new PostDetailViewModel { PostDetailDto = _postService.GetPostDetailDto(postId), Comment = new Comment() }; //return View(_postService.GetListPostDetailDto()); // ViewBag.PostId = postId;// new SelectList(context.Photos, "Id", "Description"); return(View(model)); // return View(_postService.GetPostDetailDto(postId)); //return View(_postService.GetById(postId)); }
public async Task <IActionResult> SaveCommentAsync(PostDetailViewModel model) { if (ModelState.IsValid) { if (model.ParentCommentId > 0) { await _commentService.SaveNestedCommentAsync(model.CommentId, model.ParentCommentId, model.CommentText, CurrentUserId); } else { await _commentService.SaveAsync(model.CommentId, model.Id, model.CommentText, CurrentUserId); } } return(RedirectToAction("Post", new { id = model.Id })); }
public static Post ConvertPostDetailViewModelToPost(PostDetailViewModel postDetailViewModel) { Post post = new Post(); post.Id = postDetailViewModel.Id; post.SubTitle = postDetailViewModel.SubTitle; post.Title = postDetailViewModel.Title; post.PublishDate = postDetailViewModel.PublishDate; post.IsProvisional = postDetailViewModel.IsProvisional; post.SlugUrl = postDetailViewModel.SlugUrl; //post.Tags = postDetailViewModel.Tags; post.PostDate = postDetailViewModel.PostDate; post.Ahutor = postDetailViewModel.Ahutor; post.HtmlContent = postDetailViewModel.HtmlContent; return(post); }
public async Task <IActionResult> AddComment(PostDetailViewModel vm) { if (!ModelState.IsValid || vm.Comment == null) { return(BadRequest()); } var userId = userManager.GetUserId(User); var user = await userManager.FindByIdAsync(userId); if (_posts.AddNewComment(vm.PostId, vm.Comment, user)) { return(RedirectToAction("Detail", "Post", new { @id = vm.PostId })); } return(BadRequest()); }
public ActionResult PostDetail(int id) { var post = _db.Posts.SingleOrDefault(x => x.Id == id); if (post == null || !post.Active) { return(RedirectToAction("Index")); } var model = new PostDetailViewModel { Post = post, Posts = _db.Posts.Where(a => a.Active && a.PostCategoryID == post.PostCategoryID && a.CreateDate < post.CreateDate).OrderByDescending(a => a.CreateDate).Take(3) }; return(View(model)); }
// GET: Posts/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post post = await db.Posts.FindAsync(id); if (post == null) { return(HttpNotFound()); } PostDetailViewModel postDetailViewModel = ClassPostConverter.ConvertPostToPostDetailViewModel(post); return(View(postDetailViewModel)); }
private async void PostItemSelected(object sender, SelectedItemChangedEventArgs e) { try { var post = e.SelectedItem as PostModel; PostDetailViewModel model = new PostDetailViewModel(post); await Navigation.PushModalAsync(new NavigationPage(new PostPage(post))); //await Navigation.PushAsync(new PostPage(post)); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK"); } }