public async Task <IActionResult> PutMicroPost(int id, MicroPost microPost) { if (id != microPost.Id) { return(BadRequest()); } _context.Entry(microPost).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MicroPostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Content,UserID")] MicroPost microPost) { if (id != microPost.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(microPost); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MicroPostExists(microPost.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(microPost)); }
public async Task <ActionResult <MicroPost> > GetMicroPost(int id) { MicroPost microPost = await _context.MicroPost.FindAsync(id); if (microPost == null) { return(NotFound()); } return(microPost); }
public async Task <IActionResult> Create([Bind("ID,Content,UserID")] MicroPost microPost) { if (ModelState.IsValid) { _context.Add(microPost); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(microPost)); }
public async Task <ActionResult <MicroPost> > DeleteMicroPost(int id) { MicroPost microPost = await _context.MicroPost.FindAsync(id); if (microPost == null) { return(NotFound()); } _context.MicroPost.Remove(microPost); await _context.SaveChangesAsync(); return(microPost); }
public async Task <ActionResult <MicroPostViewModel> > PostMicroPost([FromBody] MicroPostViewModel microPostViewModel) { MicroPost micropost = new MicroPost(); string currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); ApplicationUser currentUser = await _context.Users.FirstOrDefaultAsync(x => x.Id == currentUserId).ConfigureAwait(false); micropost.Content = microPostViewModel.Content; micropost.Author = currentUser; micropost.CreatedAt = DateTime.Now; micropost.UpdatedAt = DateTime.Now; _context.MicroPost.Add(micropost); await _context.SaveChangesAsync(); return(microPostViewModel); }