public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var employeer = await _context.Employeers.FindAsync(request.Employeer.EmployeerId); if (employeer == null) { employeer = new Employeer(); await _context.Employeers.AddAsync(employeer, cancellationToken); } employeer.FirstName = request.Employeer.FirstName; employeer.LastName = request.Employeer.LastName; employeer.Email = request.Employeer.Email; await _context.SaveChangesAsync(cancellationToken); if (request.Employeer.EmployeerId == default) { await _mediator.Publish(new EmployeerCreatedEvent(employeer), cancellationToken); } return(new Response() { Employeer = employeer.ToDto() }); }
public async Task Handle(EmployeerCreatedEvent notification, CancellationToken cancellationToken) { var user = new User { Username = notification.Employeer.Email }; user.Password = _passwordHasher.HashPassword(user.Salt, _configuration["Seed:DefaultUser:Password"]); user.Roles.Add(_context.Roles.Single(x => x.Name == "Employeer")); _context.Users.Add(user); await _context.SaveChangesAsync(cancellationToken); }