コード例 #1
0
        public async Task <ActionResult> Post([FromQuery] string dataType)
        {
            if (string.IsNullOrEmpty(dataType))
            {
                return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter."));
            }

            string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType);

            if (string.IsNullOrEmpty(classRef))
            {
                return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter."));
            }

            object appModel = _altinnApp.CreateNewAppModel(classRef);

            int?partyId = HttpContext.User.GetPartyIdAsInt();

            if (partyId.HasValue)
            {
                // runs prefill from repo configuration if config exists
                await _prefillService.PrefillDataModel(partyId.ToString(), dataType, appModel);
            }

            await _altinnApp.RunCalculation(appModel);

            return(Ok(appModel));
        }
コード例 #2
0
        /// <summary>
        ///  Gets a data element (form data) from storage and performs business logic on it (e.g. to calculate certain fields) before it is returned.
        ///  If more there are more data elements of the same dataType only the first one is returned. In that case use the more spesific
        ///  GET method to fetch a particular data element.
        /// </summary>
        /// <returns>data element is returned in response body</returns>
        private async Task<ActionResult> GetFormData(
        string org,
        string app,
        int instanceOwnerId,
        Guid instanceGuid,
        Guid dataGuid,
        string dataType)
        {
            string appModelclassRef = _appResourcesService.GetClassRefForLogicDataType(dataType);

            // Get Form Data from data service. Assumes that the data element is form data.
            object appModel = await _dataService.GetFormData(
                instanceGuid,
                _altinnApp.GetAppModelType(appModelclassRef),
                org,
                app,
                instanceOwnerId,
                dataGuid);

            if (appModel == null)
            {
                return BadRequest($"Did not find form data for data element {dataGuid}");
            }

            // Trigger application business logic
            await _altinnApp.RunCalculation(appModel);

            string userOrgClaim = User.GetOrg();
            if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.InvariantCultureIgnoreCase))
            {
                await _instanceService.UpdateReadStatus(instanceOwnerId, instanceGuid, "read");
            }

            return Ok(appModel);
        }
コード例 #3
0
        /// <summary>
        ///  Gets a data element (form data) from storage and performs business logic on it (e.g. to calculate certain fields) before it is returned.
        ///  If more there are more data elements of the same dataType only the first one is returned. In that case use the more spesific
        ///  GET method to fetch a particular data element.
        /// </summary>
        /// <returns>data element is returned in response body</returns>
        private async Task <ActionResult> GetFormData(
            string org,
            string app,
            int instanceOwnerId,
            Guid instanceGuid,
            Guid dataGuid,
            string dataType)
        {
            string appModelclassRef = _appResourcesService.GetClassRefForLogicDataType(dataType);

            // Get Form Data from data service. Assumes that the data element is form data.
            object appModel = await _dataService.GetFormData(
                instanceGuid,
                _altinnApp.GetAppModelType(appModelclassRef),
                org,
                app,
                instanceOwnerId,
                dataGuid);

            if (appModel == null)
            {
                return(BadRequest($"Did not find form data for data element {dataGuid}"));
            }


            // Trigger application business logic
            await _altinnApp.RunCalculation(appModel);

            return(Ok(appModel));
        }