Пример #1
0
        public async Task <IActionResult> Dislike(LikePostModel like)
        {
            var command       = new DislikePostCommand(like.PostID, like.UserID);
            var commandResult = await _dispatcher.Send(command);

            return(commandResult.IsSuccess ? Ok() : StatusCode(StatusCodes.Status500InternalServerError));
        }
Пример #2
0
        public async Task <IActionResult> Likes(int idPost)
        {
            try
            {
                var userId = await GetUserIdentityAsync();

                var statusLikePostModel = await _likePostServices.GetStatusAsync(userId, idPost);

                if (statusLikePostModel == null)
                {
                    var likePostModel = new LikePostModel
                    {
                        PostModelId  = idPost,
                        IdentityUser = userId
                    };

                    await _likePostServices.CreateAsync(likePostModel);

                    return(RedirectToAction("Index", "Home"));
                }


                await _likePostServices.DeleteAsync(statusLikePostModel.Id);

                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #3
0
        public async Task SendLikes(string userId, string postId)
        {
            Like like = _context.Likes.FirstOrDefault(x => x.postId == postId && x.userId == userId);

            if (like == null)
            {
                await _context.Likes.AddAsync(new Like
                {
                    Id     = Guid.NewGuid().ToString(),
                    userId = userId,
                    postId = postId
                });
            }
            else
            {
                _context.Likes.Remove(like);
            };
            await _context.SaveChangesAsync();

            LikePostModel model = new LikePostModel
            {
                postId        = postId,
                countsOfLikes = _context.Likes.Where(x => x.postId == postId).Count(),
                isLiked       = _context.Likes.Where(x => x.postId == postId).Select(x => x.userId).Contains(userId),
                userId        = userId
            };
            string userWhoToSend = _context.Posts.FirstOrDefault(x => x.Id == postId).userId;
            var    userWhoLiked  = await _context.UserInfo.FindAsync(userId);

            if (model.isLiked && userWhoToSend != userWhoLiked.Id)
            {
                await this.CreateNotification(userWhoToSend, "like", $"New like from {userWhoLiked.FirstName} {userWhoLiked.SecondName}", userWhoLiked.Avatar, postId);
            }
            await Clients.All.SendAsync("NewLike", model);
        }
Пример #4
0
        public async Task CreateAsync(LikePostModel likePostModel)
        {
            var path = $"{_projetoHttpOptions.CurrentValue.LikePostPath}";

            var httpContent = new StringContent(JsonConvert.SerializeObject(likePostModel), Encoding.UTF8, "application/json");

            var httpResponseMessage = await _httpClient.PostAsync(path, httpContent);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
            }
        }
Пример #5
0
        public async Task <IActionResult> Like(LikePostModel like)
        {
            var command       = new LikePostCommand(like.PostID, like.UserID);
            var commandResult = await _dispatcher.Send(command);

            if (commandResult.IsSuccess)
            {
                var postLikedNotification = new PostLikedEvent(
                    User.Identity.Name,
                    Url.Action("Profile", "Account", new { id = User.Identity.Name }),
                    like.PostID,
                    Url.Action("Detail", "Post", new { id = like.PostID })
                    );

                await _dispatcher.Publish(postLikedNotification);
            }

            return(commandResult.IsSuccess ? Ok() : StatusCode(StatusCodes.Status500InternalServerError));
        }
Пример #6
0
        public async Task <ActionResult <LikePostModel> > PostLikePostModel([Bind("Id, IdentityUser,PostModelId")] LikePostModel likePostModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                _unitOfWork.BeginTransaction();
                await _likePostServices.CreateAsync(likePostModel);

                await _unitOfWork.CommitAsync();
            }
            catch (ModelValidationExceptions e)
            {
                ModelState.AddModelError(e.PropertyName, e.Message);
                return(BadRequest(ModelState));
            }

            return(base.Ok());
        }
Пример #7
0
 public async Task UpdateAsync(LikePostModel model)
 {
     throw new NotImplementedException();
 }