Exemplo n.º 1
0
        public async Task <IActionResult> OnPostSendInAsync(string id)
        {
            try
            {
                var resultDeclaration = await apiHttpClient.Get <DeclarationItem>("/api/Declaration/Get/" + id);

                if (resultDeclaration.Succeeded)
                {
                    DeclarationItemForm = resultDeclaration.Data;
                }
                else
                {
                    await errorHandler.View(this, OnGetAsync(Guid.Parse(id)), resultDeclaration.Exception);
                }

                var formData            = Request.Form.ToDictionary <KeyValuePair <string, StringValues>, string, string>(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value);
                var declarationTestItem = new DeclarationTestHelper().CreateDeclarationTestItem(formData, DeclarationItemForm.Id, DeclarationItemForm.IndicatorList);

                var result = await apiHttpClient.Post <ApiResult>("/api/Declaration/Save/", new DeclarationSave { Id = DeclarationItemForm.Id, CompanyId = DeclarationItemForm.CompanyItemId, DeclarationTestItem = declarationTestItem });

                if (result.Succeeded)
                {
                    return(RedirectToPage("/Declaration/DeclarationRead", new { id = DeclarationItemForm.DeclarationTestItem.Id }));
                }

                return(await errorHandler.View(this, OnGetAsync(Guid.Parse(id)), result.Exception));
            }
            catch (Exception exception)
            {
                return(await errorHandler.Log(this, OnGetAsync(Guid.Parse(id)), exception, DeclarationItemForm));
            }
        }
        public ApiResult <DeclarationSaveResult> AutoSave(Guid id, Guid companyId, [FromBody] IDictionary <string, string> data, List <DeclarationIndicatorGroup> indicatorList)
        {
            var declarationItem     = declarationRepository.Get <DeclarationItem>(id).Data;
            var declarationTestItem = new DeclarationTestHelper().CreateDeclarationTestItem(data, id, declarationItem.IndicatorList);

            return(declarationRepository.Save <DeclarationSaveResult>(id, companyId, declarationTestItem));
        }