Exemplo n.º 1
0
        public async Task <string?> Handle(CreateOrUpdateUserProfile request, CancellationToken cancellationToken)
        {
            var user = _authProvider.GetUser();

            var userProfile = await _writeRepository.GetOrDefault <Domain.UserProfile>(user);

            var userProfileEventDto = new UserProfileEventDto(request.UserProfile.Id, user,
                                                              request.UserProfile.Jobs.Select(UserJobModel.To));

            if (userProfile == null)
            {
                userProfile = Domain.UserProfile.Create(userProfileEventDto);
            }
            else
            {
                userProfile.Update(userProfileEventDto);
            }

            var events = await _writeRepository.Save(profile => profile.User, userProfile);

            foreach (var evt in events)
            {
                await _mediator.Publish(evt, cancellationToken);
            }

            return(userProfile.User);
        }
Exemplo n.º 2
0
        public static UserProfile Create(UserProfileEventDto userProfile)
        {
            var instance = new UserProfile();

            instance.ApplyChange(new UserProfileAdded(userProfile));

            return(instance);
        }
Exemplo n.º 3
0
        public async Task AddOrUpdate(UserProfileEventDto profile)
        {
            var dto = UserProfileReadDto.From(profile);

            foreach (var job in dto.Jobs)
            {
                await _jobRepository.Set(job.Id, job);
            }

            await _repository.Set(dto.User, dto);
        }
Exemplo n.º 4
0
 public UserProfileAdded(UserProfileEventDto userProfile)
 {
     UserProfile = userProfile;
 }
Exemplo n.º 5
0
 public UserProfileUpdated(UserProfileEventDto userProfile)
 {
     UserProfile = userProfile;
 }
Exemplo n.º 6
0
 public static UserProfileReadDto From(UserProfileEventDto profile)
 {
     return(new UserProfileReadDto(profile.Id, profile.User, profile.Jobs.Select(UserJobReadDto.From)));
 }
Exemplo n.º 7
0
 public void Update(UserProfileEventDto userProfile)
 {
     ApplyChange(new UserProfileUpdated(userProfile));
 }