public async Task <bool> Consume(string message) { ProfileEvent profileEvent = JsonConvert.DeserializeObject <ProfileEvent>(message); if (profileEvent == null) { return(false); } Domain.Entities.Profile profile = await _context.Profile.FindAsync(profileEvent.Id); if (profile == null) { Domain.Entities.Profile newProfile = new Domain.Entities.Profile { Id = profileEvent.Id, DisplayName = profileEvent.DisplayName, Avatar = profileEvent.Avatar }; _context.Profile.Add(newProfile); return(await _context.SaveChangesAsync() > 0); } return(false); }
public async Task <Response <FollowDto> > CreateFollow(Guid profileId, Guid followerId) { var response = new Response <FollowDto>(); var profile = await _context.Profile.FindAsync(profileId); var follower = await _context.Profile.FindAsync(followerId); var followConnectionExist = await _context.Follows.FirstOrDefaultAsync(x => x.Profile == profile && x.Follower == follower); if (followConnectionExist != null) { return(response); } var follow = new Follow { Id = new Guid(), Profile = profile, Follower = follower, DateOfCreation = DateTime.Now }; _context.Follows.Add(follow); var success = await _context.SaveChangesAsync() > 0; if (success) { SendNewFollowEvent(follow.Profile.Id, follow.Follower.Id); response.Data = _mapper.Map <FollowDto>(follow); response.Success = true; } return(response); }