public IActionResult NewPost([FromBody] NewPostRequest request) { Post post = new Post(request, currentUser); context.Posts.Add(post); context.SaveChanges(); return(Created("", new PostResponse(post, currentUser))); }
public ActionResult Create([Bind(Include = "GossipId,FilmName,Genre,GossipText")] Gossip gossip) { if (ModelState.IsValid) { db.Gossips.Add(gossip); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gossip)); }
public IActionResult NewComment(int postId, [FromBody] NewCommentRequest request) { if (context.Posts.FirstOrDefault(p => p.Id == postId) == null) { return(NotFound()); } Comment comment = new Comment(request, currentUser, postId); context.Comments.Add(comment); context.SaveChanges(); return(Ok(new CommentResponse(comment, currentUser))); }
private IActionResult AddLike(int id, PostType type) { if (type == PostType.Post) { if (context.Posts.FirstOrDefault(p => p.Id == id) == null) { return(NotFound()); } } else { if (context.Comments.FirstOrDefault(p => p.Id == id) == null) { return(NotFound()); } } Like like = context.Likes.FirstOrDefault(l => l.PostId == id && l.PostType == type); bool isNew = like == null; if (isNew) { like = new Like(id, currentUser, type); context.Likes.Add(like); } else { context.Likes.Remove(like); } context.SaveChanges(); return(isNew ? (IActionResult)Created("", null) : NoContent()); }
public string SignUp(SignupRequest request) { User user = new User(request, env.DefaultProfilePicture); context.Users.Add(user); context.SaveChanges(); return(GenerateJwt(user)); }