public async Task <Response <KweetDto> > CreateKweetAsync(Guid profileId, string message)
        {
            var response = new Response <KweetDto>();
            var profile  = await _context.Profiles.FindAsync(profileId);

            if (profile == null)
            {
                return(response);
            }

            var kweet = new Kweet
            {
                Id             = Guid.NewGuid(),
                Profile        = profile,
                Message        = message,
                DateOfCreation = DateTime.Now
            };


            await _context.Kweets.AddAsync(kweet);

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                response.Success = true;
                response.Data    = _mapper.Map <KweetDto>(kweet);
            }

            return(response);
        }
        public async Task <Response <int> > CreateLikeAsync(Guid profileId, Guid kweetId)
        {
            var response = new Response <int>();

            var kweet = await _context.Kweets.FindAsync(kweetId);

            var profile = await _context.Profiles.FindAsync(profileId);

            var like = new Like
            {
                Id             = Guid.NewGuid(),
                ProfileId      = profile.Id,
                KweetId        = kweet.Id,
                DateOfCreation = DateTime.Now
            };

            await _context.Likes.AddAsync(like);

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                response.Data    = kweet.Likes.Count();
                response.Success = true;
            }

            return(response);
        }
        public async Task <bool> Consume(string message)
        {
            ProfileEvent profileEvent = JsonConvert.DeserializeObject <ProfileEvent>(message);

            if (profileEvent == null)
            {
                return(false);
            }

            Domain.Entities.Profile profile = await _context.Profiles.FindAsync(profileEvent.Id);

            if (profile == null)
            {
                Domain.Entities.Profile newProfile = new Domain.Entities.Profile
                {
                    Id          = profileEvent.Id,
                    DisplayName = profileEvent.DisplayName,
                    Avatar      = profileEvent.Avatar
                };

                _context.Profiles.Add(newProfile);
                return(await _context.SaveChangesAsync() > 0);
            }
            return(false);
        }
        public async Task <bool> Consume(string message)
        {
            FollowEvent followEvent = JsonConvert.DeserializeObject <FollowEvent>(message);

            Domain.Entities.Profile profile = await _context.Profiles.FindAsync(followEvent.ProfileId);

            Domain.Entities.Profile follower = await _context.Profiles.FindAsync(followEvent.FollowerId);

            Domain.Entities.Follow follow = await _context.Follows.FirstOrDefaultAsync(x =>
                                                                                       x.Profile == profile && x.Follower == follower);

            if (follow != null)
            {
                _context.Follows.Remove(follow);
                return(await _context.SaveChangesAsync() > 0);
            }

            return(false);
        }
        public async Task <bool> Consume(string message)
        {
            var followEvent = JsonConvert.DeserializeObject <FollowEvent>(message);
            var profile     = await _context.Profiles.FindAsync(followEvent.ProfileId);

            var follower = await _context.Profiles.FindAsync(followEvent.FollowerId);

            var followConnectionExist = await _context.Follows.FirstOrDefaultAsync(x =>
                                                                                   x.Profile == profile && x.Follower == follower);

            if (followConnectionExist == null)
            {
                var newFollow = new Domain.Entities.Follow
                {
                    Id       = Guid.NewGuid(),
                    Profile  = profile,
                    Follower = follower
                };
                _context.Follows.Add(newFollow);
                return(await _context.SaveChangesAsync() > 0);
            }

            return(false);
        }