Example #1
0
        public async Task insertPostLike(Post_Like post_Like)
        {
            dataContext = new DataContext();
            var commment_like_collection = dataContext.getConnection().GetCollection <Post_Like>("Post_Like");
            await commment_like_collection.InsertOneAsync(post_Like);

            Debug.WriteLine("Inserted post like: " + post_Like.post_id);
        }
Example #2
0
        public async Task <IActionResult> like(int userid, int postid)
        {
            /*  if(userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
             *    return Unauthorized();
             */
            var account = await _repo.GetAccount(userid);

            if (account == null)
            {
                return(BadRequest("There is not a user"));
            }

            var post = await _repo.GetPost(postid);

            if (post == null)
            {
                return(BadRequest("There is not a post"));
            }

            var like = await _repo.GetLike(userid, postid);

            if (like != null)
            {
                return(BadRequest("Already liked"));
            }

            Post_Like pt = new Post_Like();

            pt.AccountId = userid;
            pt.Post_id   = postid;
            _repo.Add(pt);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Adding music preference failed on save");
        }
Example #3
0
        public IActionResult Like(int num, string word)
        {
            // if(HttpContext.Session.GetInt32("id") == null) {
            //     return RedirectToAction("Logout");};

            Post it   = _context.posts.Include(g => g.Post_Likes).ThenInclude(a => a.Liked_Post).SingleOrDefault(u => u.Postid == num);
            User user = _context.users.SingleOrDefault(u => u.Userid == HttpContext.Session.GetInt32("id"));

            Post_Like newl = new Post_Like {
                Userid         = user.Userid,
                Liked_Post     = user,
                Postid         = it.Postid,
                Has_Post_Likes = it
            };

            it.Post_Likes.Add(newl);
            _context.SaveChanges();

            if (word == "game")
            {
                return(RedirectToAction("Game"));
            }
            return(RedirectToAction("Wall"));
        }