コード例 #1
0
        public IActionResult NewPost([FromBody] NewPostRequest request)
        {
            Post post = new Post(request, currentUser);

            context.Posts.Add(post);
            context.SaveChanges();

            return(Created("", new PostResponse(post, currentUser)));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        public string SignUp(SignupRequest request)
        {
            User user = new User(request, env.DefaultProfilePicture);

            context.Users.Add(user);
            context.SaveChanges();

            return(GenerateJwt(user));
        }