public async Task <Unit> Handle(QuickAddCandidateCommand request, CancellationToken cancellationToken) { var user = _userAccessor.GetUser(); var job = await _context.JobPositions.FindAsync(request.JobPositionId); var entity = new Candidate(CompoundName.Create(request.FirstName, request.LastName).Value, job, ContactInfo.Create(request.PhoneNumber, request.Email).Value); var stage = await _context.RecruitmentStages.FindAsync(request.RecruitmentStageId); stage.AddCandidate(entity); _context.RecruitmentStages.Update(stage); await _context.SaveChangesAsync(cancellationToken); // Notifications var notification = new CandidateCreated { PrimaryEntityId = entity.Id, PrimaryEntityName = entity.Name.GetFullName, UserName = user.Identity.Name }; await _mediator.Publish(notification, cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(CreateCandidateCommand request, CancellationToken cancellationToken) { var user = _userAccessor.GetUser(); //TODO:Import the finder extension from Renson projects var job = await _context.JobPositions.FindAsync(request.JobPositionId); var stage = await _context.RecruitmentStages.FindAsync(request.RecruitmentStageId); var entity = new Candidate(CompoundName.Create(request.FirstName, request.LastName).Value, job, ContactInfo.Create(request.PhoneNumber, request.Email).Value); var operation = stage.AddCandidate(entity); if (operation.IsFailure) { throw new InvalidOperationException(operation.Error); } _context.RecruitmentStages.Update(stage); await _context.SaveChangesAsync(cancellationToken); // Notifications var notification = new CandidateCreated { PrimaryEntityId = entity.Id, UserName = user.Identity.Name }; await _mediator.Publish(notification, cancellationToken); return(Unit.Value); }