public async Task <IActionResult> UpdateAsync(int id, [FromBody] RecoveryDto input) { // Map. var recovery = _mapper.Map <Recovery>(input); recovery.Id = id; Recovery recovery_existing = await _recoveryRepository.GetByIdAsync(id); if (recovery_existing.Attribution.Creator == input.Reviewer) { throw new AuthorizationException(); } // Act. await _recoveryRepository.UpdateAsync(recovery); // FUTURE: Does this make sense? // Only when this item was rejected can we move into // a pending state after update. if (recovery.State.AuditStatus == AuditStatus.Rejected) { // Transition. recovery.State.TransitionToPending(); // Act. await _recoveryRepository.SetAuditStatusAsync(recovery.Id, recovery); } // Return. return(NoContent()); }
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)); }