public async Task <IActionResult> UpdateContractorRecruiter([FromRoute] Guid organizationId, [FromRoute] Guid personId, [FromBody] UpdateContractorRecruiterInput input) { var result = await _contractorService .UpdateRecruiter <AgencyOwnerOrganizationContractorOutput>(_agencyOwner, personId, input); return(Ok(result)); }
public async Task <T> UpdateRecruiter <T>(IAgencyOwner agencyOwner, Guid contractorId, UpdateContractorRecruiterInput input) where T : AgencyOwnerOrganizationContractorOutput { var entity = await Repository.Queryable() .Include(x => x.Contractor) .ThenInclude(x => x.OrganizationContractors) .ThenInclude(x => x.Contracts) .Include(x => x.Contractor) .ThenInclude(x => x.OrganizationRecruiter) .FindById(contractorId, agencyOwner.OrganizationId) .FirstAsync(); var recruiter = await _recuiterRepository.Queryable() .FirstAsync(x => x.RecruiterId == input.RecruiterId && x.OrganizationId == agencyOwner.OrganizationId); entity.Contractor.OrganizationRecruiter = recruiter; entity.Contractor.ObjectState = ObjectState.Modified; entity.Contractor.Updated = DateTimeOffset.UtcNow; if (input.UpdateAllContracts) { foreach (var contract in entity.Contracts) { contract.OrganizationRecruiter = recruiter; contract.UpdatedById = _userInfo.UserId; contract.Updated = DateTimeOffset.UtcNow; contract.ObjectState = ObjectState.Modified; } } Repository.InsertOrUpdateGraph(entity, true); var response = await Repository.Queryable() .FindById(contractorId, agencyOwner.OrganizationId) .ProjectTo <T>(ProjectionMapping) .FirstOrDefaultAsync(); return(response); }