コード例 #1
0
ファイル: LikeService.cs プロジェクト: voroniak/SocialNetwork
        public async Task AddAsync(LikePostDto likePostDto)
        {
            var itemForCheckIsExcist = await _mongoRepository
                                       .FilterByAsync(l => l.UserId == likePostDto.UserId && l.LikedEntityId == likePostDto.LikedEntityId);

            if (itemForCheckIsExcist != null)
            {
                throw new ArgumentException("User has already liked this entity");
            }
            await _mongoRepository.InsertOneAsync(_mapper.Map <LikePostDto, Like>(likePostDto));
        }
コード例 #2
0
        public JsonResult DislikePost(string postId)
        {
            var post = new LikePostDto()
            {
                PostId = postId, UserId = HttpContext.User.Identity.Name, IsLike = false
            };
            var result = _postService.LikePost(post);

            return(Json(new
            {
                success = true,
                count = result.LikeCount
            }));
        }
コード例 #3
0
        public PostDto LikePost(LikePostDto likePostDto)
        {
            var request = new RestSharp.RestRequest(PostAPI.Like)
            {
                JsonSerializer = new NewtonsoftJsonSerializer()
            };

            request.AddJsonBody(likePostDto);

            IRestResponse response = _client.Post(request);
            var           json     = JsonConvert.DeserializeObject <GenericAPIResponse>(response.Content);

            if (json.success)
            {
                var postDto = JsonConvert.DeserializeObject <PostDto>(json.result.ToString());
                return(postDto);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
 public PostDto UnlikePost(LikePostDto likePostDto)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
        public async Task <IActionResult> Add(LikePostDto likePostDto)
        {
            await _likeService.AddAsync(likePostDto);

            return(Created("Add", likePostDto));
        }