public ActionResult Index(int?page = 1) { int pagenumber = (page ?? 1) - 1; int totalCount = _iapiResponse.Get <int>("home"); List <PostDTO> listPostDTO = _iapiResponse.Get <List <PostDTO> >("home?page=" + pagenumber); List <PostVM.PostIndexVM> listIndexPostVM = _imapper.Map <List <PostDTO>, List <PostVM.PostIndexVM> >(listPostDTO); IPagedList <PostVM.PostIndexVM> postIndex = new StaticPagedList <PostVM.PostIndexVM>(listIndexPostVM, pagenumber + 1, 5, totalCount); return(View(postIndex)); }
public ActionResult Details(int?id, string slug, int?page = 1) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int pagenumber = (page ?? 1) - 1; int totalCount = _iapiResponse.Get <int>("tags/" + id); List <PostDTO> listPostDTO = _iapiResponse.Get <List <PostDTO> >("tags/" + id.GetValueOrDefault() + "?slug=" + slug + "&page=" + pagenumber); List <PostVM.PostIndexVM> listIndexPostVM = _imapper.Map <List <PostDTO>, List <PostVM.PostIndexVM> >(listPostDTO); ViewBag.NameTag = slug; if (!listIndexPostVM.Any()) { return(HttpNotFound()); } IPagedList <PostVM.PostIndexVM> postIndex = new StaticPagedList <PostVM.PostIndexVM>(listIndexPostVM, pagenumber + 1, 5, totalCount); return(View(postIndex)); }
public ActionResult Edit() { UserDTO userDTO = _iapiResponse.Get <UserDTO>("users?value=" + User.Identity.GetUserName()); AccountVM.EditUserViewModel userVM = new AccountVM.EditUserViewModel(); userVM.DisplayName = userDTO.DisplayName; userVM.ImageUser = ImageFunction.ConvertImage(userDTO.ImageUser); if (userDTO == null) { return(HttpNotFound()); } return(View(userVM)); }
public ActionResult Details(int?id, string slug) { if (string.IsNullOrEmpty(slug)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostDTO postDTO = _iapiResponse.Get <PostDTO>("posts/" + id + "?slug=" + slug); PostVM.PostDetailVM postVM = _imapper.Map <PostDTO, PostVM.PostDetailVM>(postDTO); postVM.ListComment = _imapper.Map <List <CommentDTO>, List <CommentVM> >(postDTO.ListCommentDTO); postVM.IsMySelf = _iapiResponse.Get <bool>("posts/" + id + "?email=" + User.Identity.GetUserName()); TempData["Url"] = slug; if (postVM == null) { return(HttpNotFound()); } return(View(postVM)); }
public ActionResult Create([Bind(Include = "PostId,CommentContent")] CommentVM comment) { string url = TempData["Url"] as string; if (ModelState.IsValid) { CommentDTO commentDTO = _imapper.Map <CommentVM, CommentDTO>(comment); commentDTO.Email = User.Identity.GetUserName(); int? result = ConvertString.ConvertToInt(_iapiResponse.Post <CommentDTO>("comments", commentDTO)); UserDTO user = _iapiResponse.Get <UserDTO>("users?value=" + User.Identity.GetUserName()); comment.DisplayName = user.DisplayName; comment.CreateDate = DateTime.Now; comment.ImageUser = ImageFunction.ConvertImage(user.ImageUser); if (result == null) { ModelState.AddModelError("", "Can not sent your comment"); } return(PartialView("_CommentsPartial", comment)); } return(RedirectToAction("Details", "Posts", new { id = comment.PostId, slug = url })); }