public async Task <Unit> Handle(UpdateRfaCommand request, CancellationToken cancellationToken) { var id = new UserId(request.User.Id); var userToUpdated = await _repositoryUser.GetById(id); if (userToUpdated == null) { throw new UserNotFoundForUpdateException(); } var role = await _roleRepository.GetRole(request.User.Role.Name); if (role == null) { throw new RoleNotFoundForUpdateUserException(); } var email = new Email(request.Email); var existEmail = await _repositoryUser.CheckMailExist(id, email); if (existEmail) { throw new EmailAlreadyAffectedException(); } userToUpdated.UpdateFirstName(request.User.FirstName); userToUpdated.UpdateLastName(request.User.LastName); userToUpdated.UpdateEmail(request.Email); userToUpdated.UpdateRole(role); await _repositoryUser.Update(userToUpdated); var rfa = await _repository.GetRfaByEmail(userToUpdated.Email); if (rfa == null) { // cas d'un changement de role mais avec un utilisateur qui existe déjà rfa = Rfa.Create( userToUpdated.Id, new Email(request.User.Email), new PhoneNumber(request.PhoneNumber), new Profession(request.Profession)); await _repository.Add(rfa); } else { rfa = Rfa.Update(rfa, new Email(request.User.Email), new PhoneNumber(request.PhoneNumber), new Profession(request.Profession)); await _repository.Update(rfa); } return(new Unit()); }
public async Task UpdateRfa() { var email = "*****@*****.**"; var role = ExampleContext.Roles.AsEnumerable().FirstOrDefault(x => x.Name.Value == "rfa"); var addrfaCommand = new AddRfaCommand(new AddUserRfaCommand("test", "test", email, new RoleUserRfa(role.Name.Value, role.Permissions.Value)), "0678925355", "profession"); await _rfaCommandHandler.Handle(addrfaCommand, default); var id = (await _rfaRepository.GetRfaByEmail(new Email(email))).UserId.Value; var updateCommand = new UpdateRfaCommand(new UpdateUserRfaCommand(id, "test", "test", email, new RoleUserRfa("rfa", 33)), "0678925355", "professionUpdated", email); await _rfaCommandHandler.Handle(updateCommand, default); var rfaAdded = await _rfaRepository.GetRfaByEmail(new Email(email)); rfaAdded.Should().NotBeNull(); rfaAdded.Profession.Value.Should().Be("professionUpdated"); Dbconnection.Execute("DELETE FROM RFAINFO where email = @Email", new { Email = email }); Dbconnection.Execute("DELETE FROM [User] where email = @Email", new { Email = email }); }
public async Task <Unit> Update(UpdateRfaCommand updateRfaCommand) { return(await _mediator.Send(updateRfaCommand)); }