public async Task <ActionResult <Instance> > PutProcess( int instanceOwnerPartyId, Guid instanceGuid, [FromBody] ProcessState processState) { Instance existingInstance; existingInstance = await _instanceRepository.GetOne(instanceOwnerPartyId, instanceGuid); if (existingInstance == null) { return(NotFound()); } string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType; string taskId = null; if (processState?.CurrentTask?.FlowType != null && !processState.CurrentTask.FlowType.Equals("CompleteCurrentMoveToNext")) { altinnTaskType = processState.CurrentTask.AltinnTaskType; taskId = processState.CurrentTask.ElementId; } string action; switch (altinnTaskType) { case "data": case "feedback": action = "write"; break; case "confirmation": action = "confirm"; break; default: action = altinnTaskType; break; } bool authorized = await _authorizationHelper.AuthorizeInstanceAction(HttpContext.User, existingInstance, action, taskId); if (!authorized) { return(Forbid()); } // Archiving instance if process was ended if (existingInstance.Process.Ended == null && processState?.Ended != null) { existingInstance.Status ??= new InstanceStatus(); existingInstance.Status.IsArchived = true; existingInstance.Status.Archived = processState.Ended; } existingInstance.Process = processState; existingInstance.LastChangedBy = User.GetUserOrOrgId(); existingInstance.LastChanged = DateTime.UtcNow; Instance updatedInstance; updatedInstance = await _instanceRepository.Update(existingInstance); updatedInstance.SetPlatformSelfLinks(_storageBaseAndHost); return(Ok(updatedInstance)); }
public async Task <ActionResult <Instance> > PutProcess( int instanceOwnerPartyId, Guid instanceGuid, [FromBody] ProcessState processState) { string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}"; Instance existingInstance; try { existingInstance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId); } catch (Exception e) { string message = $"Unable to find instance {instanceId} to update: {e}"; _logger.LogError(message); return(NotFound(message)); } if (existingInstance == null) { return(NotFound()); } string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType; string action; switch (altinnTaskType) { case "data": case "feedback": action = "write"; break; case "confirmation": action = "confirm"; break; default: action = altinnTaskType; break; } bool authorized = await _authorizationHelper.AuthorizeInstanceAction(HttpContext.User, existingInstance, action); if (!authorized) { return(Forbid()); } // Archiving instance if process was ended if (existingInstance.Process.Ended == null && processState.Ended != null) { existingInstance.Status ??= new InstanceStatus(); existingInstance.Status.IsArchived = true; existingInstance.Status.Archived = processState.Ended; } existingInstance.Process = processState; existingInstance.LastChangedBy = User.GetUserOrOrgId(); existingInstance.LastChanged = DateTime.UtcNow; Instance updatedInstance; try { updatedInstance = await _instanceRepository.Update(existingInstance); updatedInstance.SetPlatformSelfLinks(_storageBaseAndHost); } catch (Exception e) { _logger.LogError($"Unable to update instance object {instanceId}. Due to {e}"); return(StatusCode(500, $"Unable to update instance object {instanceId}: {e.Message}")); } return(Ok(updatedInstance)); }