public async Task <IActionResult> CreateAsync(int recoveryId, [FromBody] RecoverySampleDto input, [FromServices] IGeocoderTranslation geocoderTranslation) { Address address = await geocoderTranslation.GetAddressIdAsync(input.Address); // Map. var recoverySample = _mapper.Map <RecoverySample>(input); recoverySample.Address = address.Id; recoverySample.Recovery = recoveryId; // Act. // FUTURE: Too much logic Recovery recovery = await _recoveryRepository.GetByIdAsync(recoverySample.Recovery); if (!recovery.State.AllowWrite) { throw new EntityReadOnlyException(); } recoverySample = await _recoverySampleRepository.AddGetAsync(recoverySample); recovery.State.TransitionToPending(); await _recoveryRepository.SetAuditStatusAsync(recovery.Id, recovery); // Map. var output = _mapper.Map <RecoverySampleDto>(recoverySample); // Return. return(Ok(output)); }
public async Task <IActionResult> GetAsync(int id) { // Act. Recovery recovery = await _recoveryRepository.GetByIdAsync(id); // Map. var output = _mapper.Map <RecoveryDto>(recovery); // Return. return(Ok(output)); }