Exemplo n.º 1
0
        public bool ChangeReaction(int postId)
        {
            var isBanned = unitOfWork.Users.Query.FirstOrDefault(e => e.Id == CurrentUser.Id)?.IsBanned ?? false;

            if (isBanned)
            {
                return(unitOfWork.Reactions.Query.Any(e => e.PostId == postId && e.UserId == CurrentUser.Id));
            }
            var reaction = unitOfWork.Reactions.Query.FirstOrDefault(e => e.PostId == postId && e.UserId == CurrentUser.Id);

            if (reaction == null)
            {
                var reaction2 = new Domain.Reaction()
                {
                    PostId = postId,
                    UserId = CurrentUser.Id
                };
                unitOfWork.Reactions.Add(reaction2);
                unitOfWork.SaveChanges();
                return(true);
            }
            else
            {
                unitOfWork.Reactions.Remove(reaction);
                unitOfWork.SaveChanges();
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task Consume(ConsumeContext <CreateReaction> context)
        {
            var reaction = new Domain.Reaction(context.Message.Id, context.Message.Bucket, context.Message.BlobId, context.Message.UserId, context.Message.FileId, context.Message.Index, context.Message.Fields);

            await session.Add(reaction);

            await session.Commit();
        }