public async Task <IActionResult> DeleteConfirmed(int id) { AspNetPost post = await repo.GetByIdAsync(id); await repo.DeleteAsync(post); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Comments(int id) { AspNetPost post = await repo.GetByIdAsync(id); if (post == null) { return(NotFound()); } return(View(post)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,Image,IsEdited,Created,UserId")] AspNetPost post) { if (ModelState.IsValid) { post.Created = DateTime.Now; post.FkUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); await repo.AddAsync(post); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(post.FkUserId); return(View(post)); }
public async Task <IActionResult> Reply(int id, [Bind("Description,PostId,Image,IsEdited,Created,UserId")] AspNetComment comment) { AspNetPost post = await repo.GetByIdAsync(id); if (ModelState.IsValid) { comment.Created = DateTime.Now; comment.FkUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); comment.FkPostId = post.PkId; await commentRepo.AddAsync(comment); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(post.FkUserId); return(View(post)); }
// GET: Posts/Edit/5 public async Task <IActionResult> Edit(int id) { AspNetPost post = await repo.GetByIdAsync(id); if (post == null) { return(NotFound()); } if (post.FkUserId != User.FindFirstValue(ClaimTypes.NameIdentifier)) { return(NotFound()); } ViewData["UserId"] = new SelectList(post.FkUserId); return(View(post)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,Image,IsEdited,Created,UserId")] AspNetPost post) { if (id != post.PkId) { return(NotFound()); } if (ModelState.IsValid) { try { AspNetPost originalPost = await repo.GetByIdAsync(id); originalPost.IsEdited = true; originalPost.Title = post.Title; originalPost.Description = post.Description; originalPost.Image = post.Image; await repo.UpdateAsync(originalPost); } catch (DbUpdateConcurrencyException) { if (!await PostExists(post.PkId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(post.FkUserId); return(View(post)); }